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?
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