# 定义一个字典存商品名称和金额
dict_product = {"电视": 1300, "冰箱": 1500, "空调": 2000, "电脑": 5000}
# 定义一个空的列表存添加的商品名称
list_product_name = []
# 一个标志位判断是否进行循环
shopping_sign = True
while shopping_sign:
shopping_or_trolley = int(input("请选择1.购物,2结账,3删除,其他查看:")) # 选择是购物还是结算、删除或查看
if shopping_or_trolley == 1:
shopping_name = input("请输入选购名称:") # 添加购物商品名称
list_product_name.append(shopping_name)
elif shopping_or_trolley == 2:
# 查询商品价格添加到金额中
money_sum = 0
for i in list_product_name:
money = dict_product.get(i)
money_sum += money
print("你需要支付的金额是:", money_sum)
while True:
# 输入支付金额判断金额是否正确进行支付
input_money = int(input("请输入支付金额:"))
if input_money == money_sum:
print("支付成功!")
shopping_sign = False # 标准位变更,跳出外层循环
break
else:
print("金额输入错误!")
elif shopping_or_trolley == 3:
shopping_del = input("请输入要删除的物品名称:") # 删除商品名称
list_product_name.remove(shopping_del)
else:
print(list_product_name) # 查询列表中的商品