in my function I want to be able to print the following list:
toppings = ["ONION, TOMATO, GREEN PEPPER, MUSHROOM, OLIVE, SPINACH"]
at any time just by typing "X" at any point in my code
>Solution :
You can just use the input() in a while True: loop to get the topping input or the X input.
toppings = ["ONION, TOMATO, GREEN PEPPER, MUSHROOM, OLIVE, SPINACH"]
added_toppings = []
def chooseToppings():
print("Type in one of our toppings and add it to your pizza. To see the full list of toppings, enter 'X'.")
while True:
x = input()
if x == "X":
print(toppings)
if x == "ONION":
added_toppings.append("ONION")
if x == "TOMATO":
added_toppings.append("TOMATO")
if x == "GREEN PEPPER":
added_toppings.append("GREEN PEPPER")
if x == "MUSHROOM":
added_toppings.append("MUSHROOM")
if x == "OLIVE":
added_toppings.append("OLIVE")
if x == "SPINACH":
added_toppings.append("SPINACH")
if x == "quit":
break
print(added_toppings)
chooseToppings()
It checks every iteration for your input.
If input = "X" it prints the list of toppings.
If input = "TOMATO" it adds "TOMATO" to the added_toppings list.
If input = "quit" it breaks the loop and prints the added_toppings list.