码迷,mamicode.com
首页 > 编程语言 > 详细

python Day05

时间:2017-07-12 20:08:03      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:编号   pen   pre   ==   魅族   odi   dig   end   auth   

#!/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

标签:编号   pen   pre   ==   魅族   odi   dig   end   auth   

原文地址:http://www.cnblogs.com/liuyibai/p/7157075.html

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