shop_list = [
('iphone',8888),
('iMac Pro',10888),
('Tesila',200000),
('bike',1020),
('mibook',1001)
]
shopping_list = []
salary = input('请输入你的工资>>>:')
if salary.isdigit():
salary = int(salary)
while True:
for index,item in enumerate(shop_list,1):
print(index,item)
user_choice = input('请输入要选择的商品序号>>>:')
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice <= len(shop_list) and user_choice > 0:
p_item = shop_list[user_choice -1 ]
shopping_list.append(p_item)
if p_item[1] <= salary:
salary -= p_item[1]
print('你购买的商品为%s,剩余金额为%s'%(p_item,salary))
elif user_choice == 'q':
for l_item in shopping_list:
print('---shopping list---',l_item,'\n还剩%s$'%(salary))
break
else:
print('输入有错误,请重新输入!')
else:
print('输入有错误,请重新输入!')