Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary Problem
#1
I'm trying to write a program that keeps a running total of a "customer's" total as they input items off a menu, which in this case happens to be my dictionary with items and costs assigned to one another. The total continues until the "customer" hits ctrl + d, which ends the program.

The issue I appear to be having is with items in the dictionary having similar names. The problem kids are "Super Burrito: 8.50", "Burrito: 7.50", "Super Quesdilla: 9.50", and "Quesadilla: 8.50" The numbers are their individual costs and for some reason, super burrito and and super quesadilla are trying to register as "super 7.5" and "super 8.5", respectively, which the system won't accept. Baja taco and taco do not seem to be an issue, so it is obviously the word "super" but I don't understand why that's a problem or how to fix it.

I'm a beginner in coding, but if anyone could please point me in the right direction or tell me which line of code is creating the problem, that would be much appreciated. Thank you!

menu = {
    "baja taco": 4.00,
    "burrito": 7.50,
    "bowl": 8.50,
    "nachos": 11.00,
    "quesadilla": 8.50,
    "super burrito": 8.50,
    "super quesadilla": 9.50,
    "taco": 3.00,
    "tortilla salad": 8.00
}

total = 0.00
while True:
    try:
        order = input("Item: ").lower()
        if order in menu:
            for item, cost in menu.items():
                cost = str(cost)
                order = order.replace(item, cost)
            total += float(order.strip("super"))
            print(f"Total: ${total:.2f}")
    except EOFError:
        print ("\n")
        break
Reply


Messages In This Thread
Dictionary Problem - by Chief816 - Apr-23-2023, 01:31 AM
RE: Dictionary Problem - by deanhystad - Apr-23-2023, 02:15 AM
RE: Dictionary Problem - by Chief816 - Apr-23-2023, 02:23 AM
RE: Dictionary Problem - by deanhystad - Apr-23-2023, 02:37 AM
RE: Dictionary Problem - by DeaD_EyE - Apr-24-2023, 10:00 AM

Forum Jump:

User Panel Messages

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