Record#
- Today I learned how to write a rock-paper-scissors game and learned about the usage of
from
. The tutorial didn't explain the meaning of this line of code, but I found out from chatgpt that it importsgetpass
and redefines it asinput
, which hides the input content. - If the user doesn't input RSP, I think they need to re-enter. CHATGPT said my code is fine, but it doesn't work in practice. After checking the correct answer, I found that this problem is not solved. Maybe I can solve it when I learn about functions later. I don't know either.
CODE#
from getpass import getpass as input
print("Rock-Paper-Scissors Game!")
print()
print("Please enter your choice: 🪨 = R, ✂️ = S, 📄 = P")
p1 = ''
p2 = ''
if p1 != "R" or p1 != "S" or p1 != "P":
p1 = input("Player 1: What's your choice? ")
print(p1)
if p2 != "R" or p2 != "S" or p2 != "P":
p2 = input("Player 2: What's your choice? ")
print(p2)
if p1 == p2:
print("It's a tie!")
elif p1 == "R" and p2 == "S":
print("Player 1 wins!")
elif p1 == "R" and p2 == "P":
print("Player 2 wins!")
elif p1 == "S" and p2 == "P":
print("Player 1 wins!")
elif p1 == "S" and p2 == "R":
print("Player 2 wins!")
elif p1 == "P" and p2 == "R":
print("Player 1 wins!")
elif p1 == "P" and p2 == "S":
print("Player 2 wins!")