+ 3
I need help...how can i print "you forgot to write a valid answer" only when the input is not rock scrissor or paper?
4 Answers
+ 4
You can use an endless loop like this:
my_choice = ''
while my_choice not in ['rock', 'scissors', 'paper']:
my_choice = input('Enter rock, scissors or paper: ')
print('You chose', my_choice)
This will keep asking the user for input until he enters either rock, paper or scissors:
Enter rock, scissors or paper: jssj
Enter rock, scissors or paper: potato
Enter rock, scissors or paper: rok
Enter rock, scissors or paper: rock
You chose rock
0
thx for help but I did it by my own:
if my_choice not in ["rock", "scrissors" , "paper"]:
print("You have to use only rock , paper or scrissors")
0
Add an else if (elif)