Using this code: #class item represents each item in the menu class Foodchoice: # constructor to initialize variables def __init__(self,name,wholesale,retail,Num_of_times): self.name=name self.wholesale=wholesale self.retail=retail self.no_of_times=Num_of_times # returns the item in string format def __str__(self): return f"{self.name} {self.wholesale} {self.retail} {self.no_of_times}" #printing the menu to restaurant manager def print_menu(menu): index=1 for i in menu: print(f"{index}. {i}") index+=1 #function to print the menu to customer def customer_menu(menu): index=1 for i in menu: print(f"{index}. {i.name} {i.retail}") index+=1 #Function to search for a item in menu with the given name def search(menu,name): for i in range(len(menu)): if menu[i].name==name.strip(): return i print(menu[i].name+" "+name) print("Item not present in menu") return -1 #Function to place order by the customer def order(menu): names=[] quantity=[] total=0 while 1: print("Enter choice") ch=int(input()) print("Enter Quantity") q=int(input()) menu[ch-1].no_of_times+=q total+=(menu[ch-1].retail*q) names.append(menu[ch-1].name) quantity.append(q) print("Do you want to continue\n1) yes\n2) no") con=int(input()) if con==2: break #5% tax on the total amount total= total + total*0.05 print("Add Tip") tip=int(input()) #Adding tip to the total total+=tip #printing customer bill print("\t\tBILL\n") #use zip function to combine names and quantity array into a single array of tuples for name,q in zip(names,quantity): print(f"{name} {q}") print("Total Bill is "+str(total)) return menu #Function to remove item from the menu def deleteItem(menu,name): index=search(menu,name) print(f"{menu[index].name} Deleted From menu") menu=menu[:index]+menu[index+1:] return menu #function to add item''' def addItem(menu): print("Enter name") name=input() print("Enter wholesale price") wholesale=int(input()) print("Enter retail price") retail= int(input()) print("Number of items") no_of_times=int(input()) menu.append(Foodchoice(name,wholesale,retail,no_of_times)) #Function to print the update menu def update_menu(): print("Enter choice to update") print("1) Name") print("2) wholesale") print("3) Retail") print("4) Num of Items") #Function to update item in the menu''' def updateitem(menu,name): index=search(menu,name) update_menu() ch=int(input()) if ch==1: print("Enter new name") name=input() menu[index].name=name elif ch==2: print("Enter new wholsale price") wholesale=int(input()) menu[index].wholesale=wholesale elif ch==3: print("Enter new retail price") retail=int(input()) menu[index].retail=retail elif ch==4: print("Enter new number of items") no=int(input()) menu[index].no_of_times=no return menu #Function to print the main menu def Menu(): print("***********MENU********") print("Select your Occupation") print("1 . Restaurant Manager") print("2 . Customer") #Function to print the restaurent manager display def restaurent_manager_menu(): print("Restaurant Manager Menu") print("1. Add Item") print("2. Delete Item") print("3. Update Item") print("4. Print Menu") #Function to write the updated menu in the file def write_to_file(filename,menu): with open(filename, "w") as f: for i in menu: f.write(f"{i.name},{i.wholesale},{i.retail},{i.no_of_times}\n") if __name__=="__main__": #array to store list of items menu=[] #reading items from file into list with open("menu.txt") as f: for line in f.readlines(): arr=line.rstrip().split(',') menu.append((arr[0],int(arr[1]),int(arr[2]),int(arr[3]))) #While the user does not exit keep looping while 1: ''' display the main menu ''' Menu() ''' Enter choice ''' ch1=int(input()) ''' if choice is 1 print restaurent manager display''' if ch1==1: restaurent_manager_menu() ''' Enter choice ''' ch2=int(input()) if ch2==1: ''' add item in the menu''' addItem(menu) elif ch2==2: ''' if choice is 2 remove a item ''' print("Enter name of dish to remove ") name=input() menu=deleteItem(menu,name) elif ch2==3: ''' if choice is 3 update the item''' print("Enter name of item to update") name=input() menu=updateitem(menu,name) elif ch2==4: ''' if choice is 4 print the menu''' print_menu(menu) else: print("*****Customer's Menu******") print("1. View Menu") print("2. Place Order") ch=int(input()) if ch==1: '''Display customers menu''' customer_menu(menu) elif ch==2: ''' invoke place order menu ''' menu=order(menu) print("1. To Continue\n 2.Exit") ch=int(input()) ''' if choice is 2 exit ''' if ch==2: break '''Store the updated menu into the file menu.txt ''' write_to_file("menu.txt", menu)
Using this code:
#class item represents each item in the menu
class Foodchoice:
# constructor to initialize variables
def __init__(self,name,wholesale,retail,Num_of_times):
self.name=name
self.wholesale=wholesale
self.retail=retail
self.no_of_times=Num_of_times
# returns the item in string format
def __str__(self):
return f"{self.name} {self.wholesale} {self.retail} {self.no_of_times}"
#printing the menu to restaurant manager
def print_menu(menu):
index=1
for i in menu:
print(f"{index}. {i}")
index+=1
#function to print the menu to customer
def customer_menu(menu):
index=1
for i in menu:
print(f"{index}. {i.name} {i.retail}")
index+=1
#Function to search for a item in menu with the given name
def search(menu,name):
for i in range(len(menu)):
if menu[i].name==name.strip():
return i
print(menu[i].name+" "+name)
print("Item not present in menu")
return -1
#Function to place order by the customer
def order(menu):
names=[]
quantity=[]
total=0
while 1:
print("Enter choice")
ch=int(input())
print("Enter Quantity")
q=int(input())
menu[ch-1].no_of_times+=q
total+=(menu[ch-1].retail*q)
names.append(menu[ch-1].name)
quantity.append(q)
print("Do you want to continue\n1) yes\n2) no")
con=int(input())
if con==2:
break
#5% tax on the total amount
total= total + total*0.05
print("Add Tip")
tip=int(input())
#Adding tip to the total
total+=tip
#printing customer bill
print("\t\tBILL\n")
#use zip function to combine names and quantity array into a single array of tuples
for name,q in zip(names,quantity):
print(f"{name} {q}")
print("Total Bill is "+str(total))
return menu
#Function to remove item from the menu
def deleteItem(menu,name):
index=search(menu,name)
print(f"{menu[index].name} Deleted From menu")
menu=menu[:index]+menu[index+1:]
return menu
#function to add item'''
def addItem(menu):
print("Enter name")
name=input()
print("Enter wholesale price")
wholesale=int(input())
print("Enter retail price")
retail= int(input())
print("Number of items")
no_of_times=int(input())
menu.append(Foodchoice(name,wholesale,retail,no_of_times))
#Function to print the update menu
def update_menu():
print("Enter choice to update")
print("1) Name")
print("2) wholesale")
print("3) Retail")
print("4) Num of Items")
#Function to update item in the menu'''
def updateitem(menu,name):
index=search(menu,name)
update_menu()
ch=int(input())
if ch==1:
print("Enter new name")
name=input()
menu[index].name=name
elif ch==2:
print("Enter new wholsale price")
wholesale=int(input())
menu[index].wholesale=wholesale
elif ch==3:
print("Enter new retail price")
retail=int(input())
menu[index].retail=retail
elif ch==4:
print("Enter new number of items")
no=int(input())
menu[index].no_of_times=no
return menu
#Function to print the main menu
def Menu():
print("***********MENU********")
print("Select your Occupation")
print("1 . Restaurant Manager")
print("2 . Customer")
#Function to print the restaurent manager display
def restaurent_manager_menu():
print("Restaurant Manager Menu")
print("1. Add Item")
print("2. Delete Item")
print("3. Update Item")
print("4. Print Menu")
#Function to write the updated menu in the file
def write_to_file(filename,menu):
with open(filename, "w") as f:
for i in menu:
f.write(f"{i.name},{i.wholesale},{i.retail},{i.no_of_times}\n")
if __name__=="__main__":
#array to store list of items
menu=[]
#reading items from file into list
with open("menu.txt") as f:
for line in f.readlines():
arr=line.rstrip().split(',')
menu.append((arr[0],int(arr[1]),int(arr[2]),int(arr[3])))
#While the user does not exit keep looping
while 1:
''' display the main menu '''
Menu()
''' Enter choice '''
ch1=int(input())
''' if choice is 1 print restaurent manager display'''
if ch1==1:
restaurent_manager_menu()
''' Enter choice '''
ch2=int(input())
if ch2==1:
''' add item in the menu'''
addItem(menu)
elif ch2==2:
''' if choice is 2 remove a item '''
print("Enter name of dish to remove ")
name=input()
menu=deleteItem(menu,name)
elif ch2==3:
''' if choice is 3 update the item'''
print("Enter name of item to update")
name=input()
menu=updateitem(menu,name)
elif ch2==4:
''' if choice is 4 print the menu'''
print_menu(menu)
else:
print("*****Customer's Menu******")
print("1. View Menu")
print("2. Place Order")
ch=int(input())
if ch==1:
'''Display customers menu'''
customer_menu(menu)
elif ch==2:
''' invoke place order menu '''
menu=order(menu)
print("1. To Continue\n 2.Exit")
ch=int(input())
''' if choice is 2 exit '''
if ch==2:
break
'''Store the updated menu into the file menu.txt '''
write_to_file("menu.txt", menu)
Add an application of threads to your restaurant project. Include a class that inherits threading and then allows the program to move on to other operations. Create threads for a log file. For example, when an object is created log it out with threads. Also add a log thread that is started each time an order object is added to the totals object. Don't let the program complete before all the logs are closed.
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 6 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)