Search code examples
pythoninputuser-inputbreak

Python User Input - Accepting Multiple Values Then Breaking


I would like for my input to keep asking for input and then breaking and running next code block when "no" is entered. The first question for input is "Who left at 2:30pm?", next it asks "Anybody else?". Names are entered and it will keep asking "anybody else?" until "no" is entered at which point the next code block should run. Please see my attached picture/snippet of my efforts and error I am obtaining here:

enter image description here

This is the code:

firstdrop = input("Who left at 2:30pm?")
df = df.drop(firstdrop)
second_drop = input("Anybody else?")
if second_drop == no:
  break
else:
    df = df.drop(second_drop)

Blockquote


Solution

  • Just change your code to:

    firstdrop = input("Who left at 2:30pm?")
    df = df.drop(firstdrop)
    while True:
        second_drop = input("Anybody else?")
        if second_drop == "no":
            break
        else:
            df = df.drop(second_drop)