码迷,mamicode.com
首页 > 其他好文 > 详细

Two day—购物车

时间:2018-05-02 19:05:56      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:foo   opp   user   hone   watch   获得   购物   输入   pre   


product_list = [
("Aphone", 5000),
("Watch",1000),
("Book", 100),
("Food", 50),
]
shopping_list = []
salary = input("Input of your salary:")
if salary.isdigit():
salary = int(salary)
while True:
for index ,item in enumerate(product_list):
print(index ,item)
user_choice = input(">>>> 你选物品")
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice <len(product_list) and user_choice >= 0:
choice_list = product_list[user_choice]
if choice_list[1] <= salary:
shopping_list.append(choice_list)
salary -= choice_list[1]
print("恭喜你获得 %s ,你的余额为 \033[31;1m %s\033[0m" %(choice_list , salary) )
else:
print("\033[41;1m 你的余额不足,请充值,谢谢!\033[0m")
else:
print("你选择的%s不在列表里"%(user_choice))
elif user_choice == "Q":
print("shopping_list")
for p in shopping_list:
print(p)
print("你剩余余额:\033[32;1m %s\033[0m"%(salary))
exit()
else:
print("你的输入有误!")



Two day—购物车

标签:foo   opp   user   hone   watch   获得   购物   输入   pre   

原文地址:https://www.cnblogs.com/smile-donggua/p/8981560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!