码迷,mamicode.com
首页 > 其他好文 > 详细

小试牛刀-购物车

时间:2019-08-14 12:26:23      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:append   int   one   pen   opp   put   ping   list   %s   

#author:张浩
#date:2019/8/14
list_goods = [
[‘iphone6s‘,5800],
[‘mac book‘,9000],
[‘coffee‘,30],
[‘python book‘,80],
[‘bicycle‘,1500]
]
while True:
salary = input(‘请输入充值金额:‘)
shopping_car = []
if salary.isdigit():
salary = int(salary)
while True:
print("以下是商品列表:")
for goods in list_goods:
print(list_goods.index(goods)+1,",",goods)
choice = input("请输入想购买的商品序列号,输入q退出:")
if choice.isdigit():
choice = int(choice)
if 0 < choice <= len(list_goods):
if list_goods[choice-1][1] <= salary:
shopping_car.append(list_goods[choice - 1])
print("已将%s商品加入购物车"%list_goods[choice-1])
salary = salary - list_goods[choice-1][1]
else :
print("余额不足,剩余钱:%s"%salary)
else:
print("输入的商品序号不存在!")
elif choice == "q":
print("已购买如下商品:")
for goods_buy in shopping_car:
print(shopping_car.index(goods_buy)+1,goods_buy)
print("余额:%s"%salary)
break
else:
print("输入有误,请重新输入!")
break
else:
print("输入有误,请重新输入!")

小试牛刀-购物车

标签:append   int   one   pen   opp   put   ping   list   %s   

原文地址:https://www.cnblogs.com/zzzhao/p/11350903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!