Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have somewhat completed the first and second steps

I would like to ask why is that when i run my codes, i get errors? here are the requirements i need to fulfill.

Call next customer
1. Display that there is no customer in wait queue if the wait is queue is empty
2. Otherwise, display the queue number of the customer in the wait queue
3. if the customer responds to the call, he is removed from the wait queue and put into another 'customer served' queue, to indicate that the customer has gotten his food
4. display a message to indicate that customer is being served





However, i'm stuck at the first part whereby it requires users to enter input and has no idea where i go wrong (states that error is in "while choice != 0"


i would like to achieve this sample output:
Menu
1.Register a customer
2. Call next customer
3. List customers in queue
4. Exit
Please choose : 1 # below is what will happen it user chooses menu option 1
May i have your name: Fad (enter input. fad as an example)


i would like to print out the name but i keep getting errors

errors:
TypeError                                 Traceback (most recent call last)
<ipython-input-16-85165eb1f15c> in <module>
     44     choice = int(input("Please choose:"))
     45     if choice == 1:
---> 46         register(wait_que, que_num)
     47         que_num += 1 # queue number will be incremented by 1. so if 100, then after that is 101
     48     elif choice == 2:

<ipython-input-16-85165eb1f15c> in register(queue, qnum)
     15 def register(queue, qnum):
     16     name = input("May i have your name ")
---> 17     queue.append[qnum, name, 0]
     18 
     19     pass

TypeError: 'builtin_function_or_method' object is not subscriptable


What I have tried:

import random # import collection from lab
from collections import deque
from time import sleep

print("Menu")
print("1. Register a customer")
print("2. Call next customer")
print("3. List customers in queue")
print("4. Exit")


def menu():
    pass

def register(queue, qnum):
    name = input("May i have your name ")
    queue.append[qnum, name, 0]
    
    pass
    
    
def call_next():
    if queue.empty:
        print("No customer in waiting queue")
    else:
        return 0
    
    
    
    pass


def list_cust():
    pass


wait_que = deque([]) # assign nothing to it
que_num = random.randint(1,5)*100
choice = ''


while choice != 0:
    menu() # print menu
    choice = int(input("Please choose:"))
    if choice == 1:
        register(wait_que, que_num)
        que_num += 1 # queue number will be incremented by 1. so if 100, then after that is 101
    elif choice == 2:
        call_next()
    elif choice == 3:
        list_cust()
    elif choice == 0:
        print("End of program")
        
    else:
        print("Invalid option...")
Posted
Updated 4-Feb-20 16:06pm
v2

1 solution

You forgot the colon.
Try:
Python
while choice != 0:
 
Share this answer
 
Comments
phil.o 4-Feb-20 10:57am    
Often so little things cause so much pain. Lego bricks, for example. And colons in python.
OriginalGriff 4-Feb-20 11:01am    
And tabs - don't forget what python can do with tabs ... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900