GIthub base 04 购物车
Posted libragyf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GIthub base 04 购物车相关的知识,希望对你有一定的参考价值。
""" 04 要求用户输入总资产,例如:2000 显示商品列表,让用户根据序号选择商品,加入购物车 购买,如果商品总额大于总资产,提示账户余额不足,否则,购买成功。 附加:可充值、某商品移除购物车 goods = [ {"name": "电脑", "price": 1999}, {"name": "鼠标", "price": 10}, {"name": "游艇", "price": 20}, {"name": "美女", "price": 998}, ] """ goods = [ {"name": "电脑", "price": 1999}, {"name": "鼠标", "price": 10}, {"name": "游艇", "price": 20}, {"name": "美女", "price": 998}, ] while True: for j in range(len(goods)): print(‘{} 号商品的信息为{}‘.format(j, goods[j])) while True: salary = input(‘请输入您的总资产‘) if salary.isdigit(): salary = int(salary) while True: chose = input("输入你想要的商品按‘b‘退出,退出") if chose == ‘b‘: exit(‘欢迎您下次再来‘) if chose.isdigit(): chose = int(chose) if chose >=0 and chose <len(goods): balance = salary - goods[chose][‘price‘] salary = balance print(‘您的余额为:‘, balance) while salary < 0: c = input("您的余额已不足请及时充值,充值请按‘c‘号,退出请按‘b‘") if c == ‘c‘: kk = input("输入您想冲值的金额") balance += int(kk) salary = balance print(‘您的当前余额为‘,balance) break if salary < 0: exit(‘您的余额不足‘) if c == ‘b‘: exit(‘欢迎您下次再来‘) else: print(‘请输入正确的商品编号‘) else: print(‘请输入数字‘)
以上是关于GIthub base 04 购物车的主要内容,如果未能解决你的问题,请参考以下文章
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段
java.util.MissingResourceException: Can't find bundle for base name init, locale zh_CN问题的处理(代码片段