1 # 买家 卖家 商品 金钱
2 li = [
3 {'name': '苹果', 'price': 10},
4 {'name': '香蕉', 'price': 20},
5 {'name': '西瓜', 'price': 30},
6 ]
7 shopping_car = {}
8 # 把货物放在货架上
9 print("欢迎光临likw水果店")
10 money = input('让我看看你的钱')
11
12 if money.isdigit() and int(money) > 0:
13 while 1:
14 for i, k in enumerate(li):
15 print('序号{},商品{},价格{}'.format(i, k['name'], k['price']))
16 choose = input('请输入您要购买的商品序号')
17 if choose.isdigit() and int(choose) < len(li):
18 num = input('您要购买的商品数量')
19 if num.isdigit():
20 if int(money) > li[int(choose)]['price']*int(num):
21 money = int(money) - li[int(choose)]['price']*int(num)
22 if li[int(choose)]['name'] in shopping_car:
23 shopping_car[li[int(choose)]['name']] = shopping_car[li[int(choose)]['name']] + int(num)
24 else:
25 shopping_car[li[int(choose)]['name']] = int(num)
26 print('购物车中的商品有{},您的余额为{}'.format(shopping_car, money))
27 else:
28 print('穷鬼,回去跟你老婆要钱!')
29 break
30 else:
31 print("咋滴,数量都不懂?")
32 else:
33 print("都说了是序号,你傻啊!")