标签:-- 表示 == enumerate inpu 退出 python git opp
a_list = [
(‘mac‘,9000),
(‘kindle‘,8000),
(‘tesla‘,6000),
(‘python book‘,105),
]
saving = input(‘输入你的钱:‘)
shopping = []
if saving.isdigit():#如果输入的为数字,转换为整型
saving = int(saving)
while True:
for i,v in enumerate(a_list,1):#enumerate在前面加编号,参数1,表示从几开始
print(i,v)
choice = input(‘选择购买商品的编号[退出:q]:‘)
if choice.isdigit():
choice = int(choice)
if choice>0 and choice<=len(a_list):
p_item = a_list[choice-1]
if p_item[1]<saving:
saving-=p_item[1]
shopping.append(p_item)
else:
print(‘余额不足,还剩%s块钱‘%saving)
print(p_item)
else:
print("商品编号不存在")
elif choice == ‘q‘:
print(‘--------------您已经购买如下商品----------------‘)
for i in shopping:
print(i)
print("您还剩%s元钱" %saving)
break
else:
print(‘非法字符‘)
else:
print("请正确输入的你钱")
标签:-- 表示 == enumerate inpu 退出 python git opp
原文地址:https://www.cnblogs.com/gskk/p/13320725.html