2
I have the following code Python
, representative of the game Pedra,Papel,Tesoura
.
import random
listChoices = ["rock","paper","scissor"]
print("Choose rock, paper or scissor to play or write exit to leave the game")
userChoice = str.lower(input("Rock,Paper or Scissor: "))
for choice in listChoices:
if userChoice != choice:
print("You have to choose one of the this three options to play: rock, paper or scissor or exit to leave the game")
break
pcChoice = random.choice(listChoices)
while userChoice != "exit":
if(userChoice == pcChoice):
print("User Choice --> ",(userChoice))
print("Pc Choice --> ",(pcChoice))
print("It's a tie")
elif ((userChoice == "rock" and pcChoice == "scissor") or (userChoice == "scissor" and pcChoice == "paper") or (userChoice == "paper" and pcChoice == "rock") ):
print("User Choice --> ",(userChoice))
print("Pc Choice --> ",(pcChoice))
print("User Wins congrats!!!!! :)")
elif ((pcChoice == "rock" and userChoice == "scissor") or (pcChoice == "scissor" and userChoice == "paper") or (pcChoice == "paper" and userChoice == "rock") ):
print("User Choice --> ",(userChoice))
print("Pc Choice --> ",(pcChoice))
print("Pc Wins Try Again!!!!! :(")
break
The problem is this every time I run the program and if the user does not write what the program asks for (rock,paper ou sciassor
) it prints the error message and terminates the program. On the other hand if it prints one of these three options apart from running the block that is inside the while
, also prints the previously described error message.
Thanks in advance.
I also created a game like this, read my code and try to understand your problem: https://repl.it/Fiza/0
– Salomão Neto