12 购物车之一(用列表)
asset_all = eval(input(“请输入总资产:”))
car_list = []
goods = [
{“name”:”电脑”,”price”: 1999},
{“name”:”鼠标”,”price”: 10},
{“name”:”游艇”,”price”: 20},
{“name”:”美女”,”price”: 998},
]
for i in goods:
print(i[\’name\’],i[\’price\’])
while True:
i2 = input(“请输入商品(y/Y进行结算):”)
if i2.lower() == \’y\’:
break
for j in goods:
if j[\’name\’] ==i2:
car_list.append(j)
print(car_list)
sum = 0
for item in car_list:
p = item[\’price\’]
sum += p
print(asset_all,sum)
if asset_all < sum:
print(“余额不足”)
else:
print(“购买成功”)