5.初探python之简单购物车

Posted zhoupeng-l

tags:

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

简单购物车功能:输入现有金额,选择购物,判断金额是否充足,结束打印当前所购物品,剩余金额等

goods_list = ((‘tesla‘,900000),(‘mate 10‘,4000),(‘apple x‘,7000),(‘bens‘,1000000),(‘movie‘,45),(‘bicycle‘,1500))
shopping_car = []
print(‘========== welcome to my shop ==========‘)
for i,v in enumerate(goods_list,1):
print(i,‘-->‘,v)
print(‘==========================================‘)
saving = input(‘please input your saving:‘)
if saving.isdigit():
saving = int(saving)
while True:
choice = input(‘plesse input your choice:‘)
if choice.isdigit():
choice = int(choice)
if choice>0 and choice<=len(goods_list):
choice_goods = goods_list[choice-1]
#print(choice_goods)
if saving >= choice_goods[1]:
saving-=choice_goods[1]
shopping_car.append(choice_goods)
else:
print(‘please input correct number!‘)
elif choice == ‘q‘:
print(‘============ your shopping car ============‘)
for i in shopping_car:
print(i)
print(‘you hava %s‘%saving)
break
else:
print(‘please input correct number!‘)

else:
print(‘please input correct number!‘)

 
































以上是关于5.初探python之简单购物车的主要内容,如果未能解决你的问题,请参考以下文章

Python初探list

python学习实例:写一个简单商城购物车的代码

python3爬虫初探之正则表达式

python之scrapy初探

Python Web框架之Django初探

python 之简单实现购物逻辑小栗子