超市结账python

2024-09-27 19:25:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图编写一个检查程序,但我不知道我在while循环中做了什么错误。有人能帮帮我吗?在

scanPrices函数:首先调用readPriceList函数从文本文件中读取价目表。显示价格字典中的所有项目。然后使用一个循环让客户输入他想要的每件商品的产品代码。每次输入产品代码时,都要检查代码是否在字典中。如果没有,则显示“项目未找到”。如果代码在字典中,则显示“找到的项目”和项目的价格。当客户没有更多的产品代码可输入时,他键入“9999”退出循环。scanPrices函数将计算、显示并返回所有订购项目的总价。在

def scanPrices():
    price_list = readPriceList()
    itemCode = 0
    totalPrice = 0
    while itemCode != 9999:
        itemCode = int(input("Enter 4-digit item code [or 9999 to stop]: "))
        if itemCode in price_list:

            print("Item found. Price:", )
        else:
            print("Item not found")
    totalPrice = totalPrice +
    print("Subtotal:$",totalPrice)
    return totalPrice

Tags: 项目函数代码客户字典产品价格price

热门问题