小试牛刀-购物车

Posted zzzhao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小试牛刀-购物车相关的知识,希望对你有一定的参考价值。

#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("输入有误,请重新输入!")

以上是关于小试牛刀-购物车的主要内容,如果未能解决你的问题,请参考以下文章

小试牛刀

ansible小试牛刀

前端试题-小试牛刀

爬虫 --- 小试牛刀

[sqoop] sqoop 小试牛刀

一维动态规划小试牛刀