Two day—购物车

Posted smile-donggua

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Two day—购物车相关的知识,希望对你有一定的参考价值。


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—购物车的主要内容,如果未能解决你的问题,请参考以下文章

Day70

(转)Python作业day2购物车

Day 16 购物车

DAY2练习-购物车

python day2 购物车作业

day01-homework_购物车程序