0

Sorry if the title is a bit vague. I'm writing a program using a while loop that asks the user to input their pizza toppings. When the user types "quit", the while loop stops. However, this will only work as expected if the user precisely types "quit" and not "Quit", "QUIT", "quiT", etc (They may accidentally do so).

Here is my code:

order = "\nWhat topping do you want? "
response = "\nWe will add that topping to your pizza. Enter 'quit' to finish ordering toppings. "
topping = ""

while topping != "quit":
    topping = input(order)
    if topping != "quit":
        print(response)

How can I make the program work as expected even when the user type "quit" in different formats?

Hazel P
  • 17
  • 4
  • just turn the input to lowercase, then check against lowercase quit – Mark Aug 01 '23 at 02:38
  • Are you really asking about how to process all input in a case-insensitive way, or are there inputs you want handled besides those that differ only in case? – BadZen Aug 01 '23 at 02:43

1 Answers1

0

You're wanting something like this:

while True: # I might be missing something but having this one be "while topping != "quit":" didn't seem to have a point
    topping = input(order)
    if topping.lower() == 'quit':
        print(response)
        break
Mark
  • 7,785
  • 2
  • 14
  • 34