python 购物小程序

#货物清单
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 到你的购物车,你现在余额还剩 33[31;1m%s33[0m" %(p_item,salary))
else:
print("33[41;1m您的余额不足!33[0m")
else:
print("33[33;1m您选的商品不存在!33[0m")
elif usr_choice ==‘Q‘:
print("------打印购物清单-----")
for i in shopping_list:
print(i)
print("你的余额还剩:33[31;1m%s33[0m"%(salary))
exit()
else:
print("33[31;1m 你输入无效!33[0m")

python 购物小程序

以上是python 购物小程序的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>