首页 > 代码库 > python Day05
python Day05
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author Jean
shopping_list = []
product_list = [
("苹果",5800),
("华为",1800),
("魅族",2200),
("oppo",1900),
("vivo",1500),
("三星",800)
]
salary = input("Please 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 into shopping cart. Your current balance \033[31;1m%s\033[0m" % (p_item, salary))
else:
print("你的余额为 %s 无法购买商品。" % (salary))
else:
print("无效的商品编号...")
elif user_choice == "q":
print("----以下为您选购的商品----")
for p in shopping_list:
print(p)
print("你的余额为 %s" % (salary))
exit(1)
else:
print("您输入的商品不存在!")
exit(1)
else:
print("Invliad Input....")
python Day05
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。