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 the following 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 the program terminates. On the other hand, if it prints one of these three options in addition to executing the block that is within while
, it also prints the previously described error message.
Thank you in advance.