二手产品经理

二手产品经理

THIS IS RENO

Learn Python in 100 Days Online - Week 2 Day 7

Record#

  1. 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 referencing getpass and redefining it as input, making the input content not visible.
  2. 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!")
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.