-4

I'm working on validating inputs in python. This is the code I have so far:

while input('Would you like to continue(y=yes/n=no)') not in ('y'): 
      print ("Sorry, I didnt catch that. Enter again: ")

The code works but I want to use two conditions, one for 'y' and one for 'n'.

martineau
  • 119,623
  • 25
  • 170
  • 301
W.Zeng
  • 1
  • 1
  • The top answer to the that question I linked above shows how to store what the input is, then you can check it to do whatever you want. – user3483203 Apr 20 '18 at 00:43

1 Answers1

1

Try this:

while True:

    ## Get their choicer
    selection = input('Your message')

    ## If yes
    if selection == 'y':
        do_something_for_y()

    ## If no
    elif selection == 'n':
        do_something_for_n()

    ## If neither, this loops to the top and asks again
cheezits
  • 96
  • 2