常用类型
shop_list = [['iphone',5800],['mac book',8000],['coffee',30],['python book',80],['bicyle',1500]]#申明一个商品列表
shop_car = []#定义一个空别表用来存放自己购买的商品
save_price = input("输入你的金额")
for i, v in enumerate(shop_list):
print(i, v)
# 打印完成后,选择要购买的商品编号
if save_price.isdigit():
save_price = int(save_price)
while True:
choice = input("输入你要购买的商品编号,退出请输入q:")
if choice.isdigit():
choice = int(choice)
if choice >=0 and choice < len(shop_list):
P_choice = shop_list[choice]#如果输入商品在商品列表中,判断价钱
if P_choice[1] < save_price:
save_price -= P_choice[1]
shop_car.append(P_choice)
else:
print("余额不足,还剩下%s 元钱" %save_price)
print(P_choice)
else:
print("商品列表不包含该商品,请重新输入")
elif choice == 'q':
print("--------打印购买商品列表----------")
for i in enumerate(shop_car):
print(i)
print("还剩%s钱"%save_price)
break
else:
print("你输入错误,请重新输入")