首页 > 其他 > 详细

shopping cart

时间:2018-08-20 15:00:43      阅读:132      评论:0      收藏:0      [点我收藏+]
product_list = [
(‘phone1‘,5000),
(‘phone2‘,4000),
(‘phone3‘,3000),
(‘phone4‘,2000),
(‘phone5‘,1000),
(‘phone6‘,100),
]
shopping_list = []
salary = input("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:
p_item = product_list[user_choice]
if p_item[1] <= salary:
shopping_list.append(p_item)
salary -= p_item[1]
print("Added %s to shopping cart,your current balance is %s"%(p_item,salary))
else:
print("only [%s],not enough "%salary)
else:
print("product code [%s] is not exist!"%user_choice)
elif user_choice == ‘q‘:
print("-------shopping_list-------")
for p in shopping_list:
print(p)
print("Your current balance is ",salary)
exit()
else:
print("Invalid option")

shopping cart

原文:https://www.cnblogs.com/lanfriend/p/9505355.html

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