0

The program is stuck at the first input, also won't respond to while True

available_toppings = ["mushrooms", "olives", "pepperoni", "pineapple"]
print(f"Hello! please choose from the available toppings:\n{available_toppings[0].title()}\n{available_toppings[1].title()}\n{available_toppings[2].title()}\n{available_toppings[3].title()}\n")
requested_toppings = input("Please choose your topping:\n")

def program():
            if requested_toppings in available_toppings:
                print(f"Adding {requested_toppings}..")
            else:
                print(f"Sorry, {requested_toppings} is not available!")

while True:
    program()
    if input("Do you want to add another topping? (Y/N)\n").strip().upper().lower() == "N":
        break
print("Finished making your pizza!")

The program should print(f"Adding{requested_toppings}..") if the user input is a value that exists in available_toppings else print(f"Sorry, {requested_toppings} is not available!") if it's not. Then ask the user if they want to add another topping. If not (N), the loop breaks and print("Finished making your pizza!") Instead it's stuck at the first input.

  • `upper().lower() == "N":` – Green_Wizard Jan 02 '23 at 00:58
  • 2
    That `.lower()` will cast your input string to lowercase, which always gets compared to a capital `N`, which will always return `False`. Removing it should solve your problem. – tehCheat Jan 02 '23 at 00:58
  • "Instead it's stuck at the first input." Did you try providing some input? What happens when you do so? Also, try to think carefully about the intended logic. Should `requested_toppings = input("Please choose your topping:\n")` happen **only once, no matter what**? Or should it happen again if the `requested_toppings` is not `in available_toppings`? (Or perhaps it should happen every time before `program` runs?) Therefore, where in the code should this be put - inside the loop, or outside/before? – Karl Knechtel Jan 02 '23 at 01:04
  • Thanks, that solved the loop break issue, but it's still stuck at the first input: If I first type "mushrooms", it will still return "Adding mushrooms" when another input is given. – cryptoboomer Jan 02 '23 at 01:05
  • Well, yes. Again, think carefully about the logic. After you have added the mushrooms, should the program ask the user again for another topping? Or should it use the existing value of `requested_toppings` again? Therefore, do we need to call `input` again? Where in the code might that go? – Karl Knechtel Jan 02 '23 at 01:06
  • Placing requested_toppings in the function solved the problem, thanks – cryptoboomer Jan 02 '23 at 01:12

0 Answers0