I want user to not be able to write characters other than 'y'and 'n' I have read from a lot of sources but none of them seems to be explaining this case.
ready = raw_input('\nOK, Ready? (y/n)\n')
I want user to not be able to write characters other than 'y'and 'n' I have read from a lot of sources but none of them seems to be explaining this case.
ready = raw_input('\nOK, Ready? (y/n)\n')
This is one way you can repeatedly ask for an input until the input is in a provided set
:
ready = ''
while ready not in {'y', 'n'}:
ready = raw_input('\nOK, Ready? (y/n)\n')
print('Success')
Note strings are case sensitive. Use str.lower
for case insensitivity.
Also relevant: Asking the user for input until they give a valid response