1

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')
jpp
  • 159,742
  • 34
  • 281
  • 339
Ezic
  • 41
  • 5

1 Answers1

0

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

jpp
  • 159,742
  • 34
  • 281
  • 339