Reputation: 3801
I am trying to figure out why any input starting with 'y' keeps this game going....looking at the code it appears only 'y' or 'yes' should keep it going but I could enter 'yensdg', 'yyyy' etc and it still loops.
Any ideas? Thanks
from random import randint
repeat = True
while repeat:
print('You rolled', randint(1,6))
print('Do you want to roll again?')
repeat = ('y' or 'yes') in input().lower()
Upvotes: 0
Views: 65
Reputation: 2776
'y' in input().lower(), this statement will return true if 'y' is present anywhere in the input string. Like if the input is 'thisisarandominputwithy' it will return true, because it has 'y' in the end
Change the last line to:
repeat = input().lower() in ['y', 'yes']
Upvotes: 1