'''
题目:
1.启动程序后 让用户输入工资 然后打印商品列表
2.允许用户根据商品编号购买商品
3.用户选择商品后,检测商品是否足够,够就直接扣款,不够就提醒
4.可随时退出,退出时,打印已经购买的商品
'''
gz = int(input('你的工资:'))
shop = ([1,'iphone',3999],[2,'mac',9999],[3,'bike',466])
q = ''
goshop = []
shop_lost = '' #购买商品列表
min_shop = 9999999999
i = 0 #计算买了第几个商品
while q != 'N' or q!='n':
for item in shop:
if min_shop > item[2]:
min_shop = item[2]
print(item[0],'.',item[1],' ',item[2])
if min_shop > gz:
print('卡上余额不足!')
print('卡上余额:', gz)
if len(goshop) == 0:
shop_lost = '\n暂无'
else:
shop_lost = '\n'.join(goshop)
print('购物车商品:')
print(shop_lost)
break
go = int(input('请选择商品:'))
sums = len(shop) # 统计数量
if go > sums:
print('该商品不存在')
if gz < shop[go-1][2]:
print('卡上余额不足!')
else:
gz -= shop[go-1][2]
shop_str = shop[go-1][1]+':'+str(shop[go-1][2])
print(shop_str)
goshop.insert(i,shop_str)
i += 1
print('卡上余额:',gz)
if len(goshop) == 0:
shop_lost = '\n暂无'
else:
shop_lost = '\n'.join(goshop)
print('购物车商品:')
print(shop_lost)
q = input('是否继续:Y/N:')
05-05
05-05
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交