# creating menu
def menu():
print("What do you want to do:")
print("1)Push")
print("2)Pop")
print("3)Display")
print("4)Quit")
choice = int(input("Make a selection: "))
return choice
# creating a queue with a list
def create_queue():
# creating a queue
queue = []
while menu() > 0 & menu() < 5:
if menu() == 1:
print("You choose: Push")
num_input = int(input("How many items do you want to enter: "))
for i in range(num_input):
queue.append(input("Enter items: "))
elif menu() == 2:
print("You choose: Pop")
# making sure queue is not empty
if len(queue) == 0:
print("Empty, nothing to get rid of.")
return
else:
print("Popping item out")
queue.pop(0)
elif menu() == 3:
print("You choose: Display")
print(queue)
elif menu() == 4:
print("You chose: Quit")
return
else:
print("Not a choice")
return
create_queue()
This is my code above, every time I run it, it would keep asking what I want to do, this is what I mean when it keeps repeating:
What do you want to do: 1)Push 2)Pop 3)Display 4)Quit Make a selection: 1 What do you want to do: 1)Push 2)Pop 3)Display 4)Quit Make a selection: 1 What do you want to do: 1)Push 2)Pop 3)Display 4)Quit Make a selection: 1 You choose: Push How many items do you want to enter:
I have tried putting user choice in the loop but it would just get stuck in one choice instead of looping back out.
I just want it to ask once and then afterwards, loop back out. Where did I mess up and what can I change to fix this?