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

购物车练习

时间:2017-08-07 00:17:33      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:dex   end   append   option   余额   app   []   product   rod   

goods=[
("iphone",5800),
("iwatch",2300),
("Huawei P9",4300),
("Mac Pro",12000),
("Book",500)
]########################商品列表
shoping_list=[]##########空表
salary=input("input You are Salary:")
if salary.isdigit():###########.isdigit整数
salary=int(salary)#####转数据为int
while True:####循环
for index,item in enumerate(goods):########虚幻index,给goods赋值
print(index,item)
user_choice=input("please choice goods...")
if user_choice.isdigit():
user_choice=int(user_choice)
if user_choice<len(goods) and user_choice>=0:
p_item=goods[user_choice]
if p_item[1]<=salary:
shoping_list.append(p_item)
salary-=p_item[1]
print("Added %s into shopping cart ,your current balanceis \033[31;1m%s\033[0m"%(p_item,salary))
else:
print("\033[41;1m你的余额不住,只剩[%s]\033[0m"%salary)
else:
print("product code [%s] is not exist!" % user_choice)
elif user_choice=="q":
print("---------------shopping list------------------")
for p in shoping_list:
print(p)
print("your current balance",salary)
exit()
else:
print("invalid option")


购物车练习

标签:dex   end   append   option   余额   app   []   product   rod   

原文地址:http://www.cnblogs.com/-zhuy/p/7296239.html

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