python Day05
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章