标签:and 商品 问题 money break bre print choice 购物车
product_list=[(‘Mac‘,9000),
(‘kindle‘,800),
(‘tesla‘,900000),
(‘book‘,50),
(‘bike‘,2000)]
money=input(‘please input your money:‘)#输入本金
shopping_car=[]
if money.isdigit():#saving是个字符串,字符串里面是数字
money=int(money)
#将商品展示给用户
#for i in product_list:
# print(product_list.index(i)+1,i)
#for i in enumerate(product_list,1):
# print(i)
while True:
for i,v in enumerate(product_list,1):
print(i, v)
choice=input(‘选择购买商品编号[退出:q]:‘)
if choice.isdigit():
choice=int(choice)
if choice>0 and choice<=len(product_list):
p_item=product_list[choice-1]
if p_item[1]<money:
money-=p_item[1]
shopping_car.append(p_item)
else:
print(‘余额不足,还剩%s‘%money)
print(p_item)
else:
print(‘编号不存在‘)
elif choice==‘q‘:
print(‘--------------您已经购买如下商品--------------‘)
for i in shopping_car:
print(i)
print(‘您的余额为%s‘%money)
break
else:
print(‘invalid input‘)
标签:and 商品 问题 money break bre print choice 购物车
原文地址:https://www.cnblogs.com/Vicky-M/p/9995964.html