标签:index book 列表 ice lis inpu iphone mac for
product_list = [
("Iphone",6000),
("Mac pro",12800),
("Bike",600),
("Watch",8000),
("Book",24),
("?offee",35),
]
shopping_list = ()
salary = (input("请输入您的购物款: "))
if salary.isdigit(): # 判断输入的值是否为数值,是的话继续
salary = int(salary)
while True:
for item in product_list:
print(product_list.index(item),item) # 打印列表的下标及列表
user_choice = input("请输入您想要购买的物品编号:")
if user_choice.isdigit():
user_choice = int(user_choice)
print("输入错误,请重新输入")
if user_choice <= len(product_list) and user_choice >= 0:
p_item = product_list[user_choice]
if p_item[1] <= salary: #能够支付
shopping_list.append(p_item) # 调用不到.append,也是醉了
salary -= p_item[1]
print("您购买的商品 %s 购买成功,余额还剩余%s"%(p_item[0],salary))
else:
print("余额不足,无法购买,请重新选择吧!")
elif user_choice == "退出":
print("退出成功,欢迎下次再来")
print("----info of shoppint_list")
for p in shopping_list:
print(p)
print("您的余额还剩余",salary)
print(shopping_list)
exit()
else:
print("输入值错误,请重新输入")
print()
标签:index book 列表 ice lis inpu iphone mac for
原文地址:http://www.cnblogs.com/y00261904--mark/p/6901334.html