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

shopping cart

时间:2018-08-20 15:38:05      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:val   only   put   int   cart   dde   print   ice   --   

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

标签:val   only   put   int   cart   dde   print   ice   --   

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

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