#先输入金额,然后通过商品编号购买,退出后有购物结算
Product = [
('Pen',5),
('Apple*3',10),
('Phone',3000),
('Fan',50),
('Ball',130),
]
Shopping_list = []
while True:
Salary = input('请输入你现有的钱:')
if Salary.isdigit():
Salary = float(Salary)
while True:
for num,x in enumerate(Product):
print(num,x)
Pro_num = input('请输入商品编号(按q可退出):')
if Pro_num.isdigit():
Pro_num = int(Pro_num)
if 0 <= Pro_num < len(Product):
Pro_item = Product[Pro_num]
if Salary >= Pro_item[1]:
Shopping_list.append(Pro_item)
Salary -= Pro_item[1]
print('商品%s已购买,你的余额为%s'%(Pro_item,Salary))
else:
print('余额不足,请选择其他商品,当前余额为:%s'%Salary)
else:
print('无此商品编号,请重试!\n')
elif Pro_num == 'q':
print('\n-----你的购物单如下------')
for x in Shopping_list:
print(x)
print('工资余额:%s'%Salary)
print('-------谢谢惠顾---------')
exit()
else:
print('无效的商品编号!')
else:
print('无效的输入,请输入数字!\n')
'''
#使List的起始下标为1
L = [15,64,16,78,384,1468]
for num,x in enumerate(L,1):
print(num,x)
'''
Python的list购物流程
猜你喜欢
转载自www.cnblogs.com/work-for-who/p/9136739.html
今日推荐
周排行