Record#
- Today I learned to write a rock-paper-scissors game and learned the usage of
from
. The tutorial did not explain the meaning of this line of code, but I found out from ChatGPT that it is referencinggetpass
and redefining it asinput
, making the input content not visible. - In the case where the user does not input R, S, or P, I think they should input again. ChatGPT said my code is correct, but it doesn't work in practice. After checking the correct answer, I found that it didn't solve this issue. Maybe I can solve it when I learn about functions later. I don't understand either.
CODE#
from getpass import getpass as input
print("Rock Paper Scissors Game!")
print()
print("Please make 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!")