代码段
f =float(input('输入你的工资'))
goods=['1.apple','2.mac','3.ph','4.python','5.php']
price=[35,26.5,14,10.5,18]
buy=[]
costs = price[0]
for gs in goods:
print("%s:\t%0.02f"%(gs,price[goods.index(gs)]))
for ps in price:
if costs > ps:
costs = ps
if f > costs:
while f >= costs:
key = input("是否购买:")
if key =='y':
lists = int(input('输入选择你要购买的商品编号:'))
cost=price[lists-1]
if f >= cost:
buy.append(goods[lists - 1])
f = f - cost
print("\n= = = = = = = = = = = = = = = = = = = = = = = = =")
print("你选择购买 %s 消费 %0.02f;余额 %0.02f"%(goods[lists-1],price[lists-1],f))
else:
print("看看就行,摸坏了要陪的!")
else:
# print("\n= = = = = = = = = = = = = = = = = = = = = = = = =")
# print("you choose %s cost %f;you over %f"%(goods[lists-1],price[lists-1],f-cost))
print("不买,看看不行吗!")
break
print("金额不足购买其他商品")
else:
print("提示:还是存钱娶老婆吧!")
测试执行
F:\Python35\python.exe F:/mologa-workspace/4th.py
输入你的工资53
1.apple: 35.00
2.mac: 26.50
3.ph: 14.00
4.python: 10.50
5.php: 18.00
是否购买:y
输入选择你要购买的商品编号:1
= = = = = = = = = = = = = = = = = = = = = = = = =
你选择购买 1.apple 消费 35.00;余额 18.00
是否购买:y
输入选择你要购买的商品编号:2
看看就行,摸坏了要陪的!
是否购买:n
不买,看看不行吗!
金额不足购买其他商品
Process finished with exit code 0