首页 > 微信 > 详细

python 购物小程序

时间:2021-01-23 10:16:42      阅读:46      评论:0      收藏:0      [点我收藏+]
#货物清单
product_list = [(‘Iphone‘,5800),
(‘Mac Pro‘,12000),
(‘coffee‘,31),
(‘Book‘,120),
(‘Bycle‘,800)]
#购物车清单
shopping_list = []
#顾客输入自己的工资
salary = input("请输入您的工资:")
if salary.isdigit():
salary = int(salary)
while True:
for index,item in enumerate(product_list):
print(index,item)
usr_choice = input("请选择你要商品:")
if usr_choice.isdigit():
usr_choice = int(usr_choice)
if usr_choice < len(product_list) and usr_choice>=0:
p_item = product_list[usr_choice]
print(p_item)
if salary >= p_item[1]: #可以购买
shopping_list.append(p_item)
salary-=p_item[1]
print("添加 %s 到你的购物车,你现在余额还剩 \033[31;1m%s\033[0m" %(p_item,salary))
else:
print("\033[41;1m您的余额不足!\033[0m")
else:
print("\033[33;1m您选的商品不存在!\033[0m")
elif usr_choice ==‘Q‘:
print("------打印购物清单-----")
for i in shopping_list:
print(i)
print("你的余额还剩:\033[31;1m%s\033[0m"%(salary))
exit()
else:
print("\033[31;1m 你输入无效!\033[0m")

python 购物小程序

原文:https://www.cnblogs.com/xiaoDK/p/14316459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!