-- coding:utf-8 --
#Author Chen
#定义商品列表
List_of_commodities = [
('Iphone',6888),
('Mac Pro',12888),
('Bike',3000),
('Book',34),
('Cut',98),
]
#定义一个空列表,用于存放已购商品
Purchased_goods = []
Amount_of_shopping = input("请输入您的购物金额:")
if Amount_of_shopping.isdigit():
Amount_of_shopping = int (Amount_of_shopping)
while True:
for index,item in enumerate(List_of_commodities):
print(index,item)
chioce = input("请输入您选择的商品编号:")
if chioce.isdigit():
chioce = int(chioce)
if chioce < len(List_of_commodities) and chioce >= 0 :
chitem = List_of_commodities[chioce]
if chitem[1] <= Amount_of_shopping:
Purchased_goods.append(chitem)
Amount_of_shopping-