Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Assistance
#5
Well done Jack, now we are getting somewhere. It is getting clear what you want. But there is still room for improvement.
You are working with lists and that is good. But now you have 2 lists and you are still printing a fixed menu. When the restaurant would like to add another dish to the menu you would have to add that in 3 places.
Look at this:
def menu(list_of_items):
    print("        Restaurant Register        ")
    print()
    print("Dish No.       Dish Name          Price")
    print("--------       ----------         ------")
    for dish in range(len(list_of_items)):
        print(f"{dish:<15}{list_of_items[dish][0]:<18}${list_of_items[dish][1]:>6.2f}")

menu_items = [['Gang Gai', 10.00],
             ['Pad Thai', 8.75]]

menu(menu_items)
Output:
Restaurant Register Dish No. Dish Name Price -------- ---------- ------ 0 Gang Gai $ 10.00 1 Pad Thai $ 8.75
First you see I defined a two-dimensional list. The list contains dishes and each dish is a list with item 0 being the dish name and item 1 being the price.
Then you see I used this list as a parameter for the menu function. In this case you might also access the list directly from the menu function as the list is in the global scope, but this is bad practice. A function should be self-contained and not rely on secret variables in another scope.

Then it gets clear the customer may order more than one dish. So it is best to have another list with the name "orders". Each chosen dish should be appended to the orders list. And at the end the bill() function should be called with two parameters. Like this:
bill(menu_items, orders)
Can you do that?
Reply


Messages In This Thread
Need Assistance - by Jack_Daniels - May-16-2020, 05:35 AM
RE: Need Assistance - by ibreeden - May-16-2020, 12:12 PM
RE: Need Assistance - by Jack_Daniels - May-16-2020, 09:57 PM
RE: Need Assistance - by Jack_Daniels - May-16-2020, 10:59 PM
RE: Need Assistance - by ibreeden - May-17-2020, 08:58 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020