2.python之购物车程序

2021-03-08 11:29

阅读:620

return _salary,lists,allpay


lists = [[‘iphone‘,999],[‘lv bag‘,666],[‘xiaomi‘,1999,],[‘honor‘,2999],[‘oppo‘,2999]]
_salary = input("please input your salary:")
allpay = 0
shoplist = []
while True:
print("商品列表如下:")
# for list in lists:
# print(f"{lists.index(list)}-{list}")
for index,list in enumerate(lists):
print(f"{index} - {list}")
_num = input("请选择你要购买的商品序号(q退出)")
if _num.isdigit():
_num = int(_num)
if _num len(lists) and _num >= 0:
choice = lists.index(lists[_num])
if _num == choice:
(_salary, lists, allpay) = shop_1(_salary, lists, allpay)
else :
print("你输入的序号不存在,请重新输入:")
else:
if _num == ‘q‘:
print("欢迎下次光临!")
print(f"你已购买{shoplist},总共花费{allpay},当前可用余额:{_salary}")
exit()
else:
print("请选择正确的商品序号。")


评论


亲,登录后才可以留言!