Empty conditional works one way but not the other?

Viewed 7

Full code example:

prompt = "Please input age of movie-goet. Output is the cost: "
prompt += "\nIf you'd like to stop testing numbers, please enter 'stop' -> "
active = True
while active:
    trigger = (input(prompt))
    if trigger == "stop" or "":
        break
    else:
        trigger = int(trigger)
        if trigger <= 3:
            print("\nYour ticket is free.\n")
        elif trigger <= 12:
            print("\nYour ticket is $10.\n")
        else:
            print("\nYour ticket is $15.\n")

If you simply hit enter, an error is thrown:

Exception has occurred: ValueError
invalid literal for int() with base 10: ''
  File "while_movie_break.py", line 9, in <module>
    trigger = int(trigger)

But if you change if trigger == "stop" or "": to "" or "stop", it works correctly. No error thrown when you hit enter with no input.

Very confused...

Thanks!

0 Answers
Related