python购物_python 购物

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的原创作品,如需转载,请注明出处,否则将追究法律责任

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值