首页 技术 正文
技术 2022年11月15日
0 收藏 463 点赞 2,141 浏览 1013 个字

要求:

  1,用户进入后,有欢迎语并提示用户输入本金

  2、用户输入正确的内容后有购物菜单显示给用户

  3、当用户的本金不足以购买商品的时候有提示余额不足并告知差额

  4、成功购物后提示已购买内容和购买后的余额,可重复多次购买

  5、结束的时候告知用户购买的商品内容及余额

print("------------******-----------")
menu = [["macbook",9000],["iphone",4500],["bick",800],["pythonbook",80],["cup",50]]
shopping_car = []
a = True
while a == True:
balance = input("请输入您拥有的金额[q退出]:")
if balance.isdigit():
balance = int(balance)
while True:
for i in range(0,len(menu)):
print(str(i + 1) + "、" + menu[i][0],menu[i][1])
choice = (input("请您输入需要的商品序号[q退出]"))
if choice.isdigit():
choice = int(choice)
if 0 < choice <= len(menu): price = int(menu[choice - 1][1])
if price <= balance:
balance -= price
shopping_car.append(menu[choice - 1])
print("已添加" + str(menu[choice - 1][0]) + "到您的购物车,余额" + str(balance) +"。请继续购物。")
else:
print("余额不足" + str(balance - price) + "请重新选择。")
elif choice == "q":
print("您购买了以下商品")
for i in range(0, len(shopping_car)):
print(str(i + 1) + "、" + shopping_car[i][0], shopping_car[i][1])
print("当前余额为:" + str(balance))
a = False
break
else:
print("请输入正确的编号")
elif balance == "q":
print("您未购买商品。")
break
else:
print("请输入正确的金额")

购物车.py

初学Python,笔记初级的编写方式。见笑。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905