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

mini购物车程序

时间:2018-05-01 15:19:36      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:user   option   else   you   mini   AC   python   sha   index   

product_list=[("Iphohe",5800),("Mac Pro Book",12900),
("xiaomi 4c",1200),("Alex python",120),
("Bike",800)]
shopping_list=[]
salary=input("input your salary:")
if salary.isdigit():
salary=int(salary)
else:
print("您的输入有误,请重新输入")

while True:
for index,shangpin in enumerate(product_list):
print(index,shangpin)

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 into shopping cart,your current balance is \033[32;1m%s\033[0m"%(p_item,salary))
else:
print("your current balance is\033[31;1m%s\033[0m,信仰不足,请充值"%(salary))
elif user_choice==‘q‘:
       print(‘______shopping list______‘)
       for a in shopping_list:
       print(a)
print("your current balance is\033[31;1m%s\033[0m,谢谢使用"%(salary) )
exit()
else:
print("invalid option")

mini购物车程序

标签:user   option   else   you   mini   AC   python   sha   index   

原文地址:https://www.cnblogs.com/qtclm/p/8976114.html

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