Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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  users enter input and will print it.able to print it but i received errors

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 5-Feb-20 5:28am

1 solution

You need parentheses around the parameters sent to the append method. See collections — Container datatypes — Python 3.8.1 documentation[^].
 
Share this answer
 

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