python 购物
# -*- coding: utf-8 -*-
import sys
salary = int(raw_input('Please input your salary:'))
products = [
['Iphone', 5800],
['MacPro', 12000],
['NB Shoes', 680],
['Cigarate', 48],
['MX4', 2500],
]
list = []
for i in products:
list.append(i[1])
if salary < min(list):
print "工资太低,买不起任何东西"
sys.exit()
low = min(list)
print low
shoplist = []
sum = 0
while True:
for p in products:
print products.index(p) ,p[0], p[1]
choice = int(raw_input("Please choice sth to buy:"))
if salary > products[choice][1]:
balance = salary - products[choice][1]
salary = balance
print '你选择 %s 价格是 %s 您的余额是 %s '% (products[choice][0] ,products[choice][1] ,balance)
shoplist.append(products[choice][0])
sum = sum + products[choice][1]
else:
if salary > low:
print "请选择有能力购买的商品。"
continue
print "金额不足,买不到东西了!\n您现在的购物车 %s 总额 %s" % (shoplist ,sum)
sys.exit()
©著作权归作者所有:来自51CTO博客作者freeterman的原创作品,如需转载,请注明出处,否则将追究法律责任