简易购物车 --day2

1062671-20161116184145951-858332871.png

代码段

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

转载于:https://www.cnblogs.com/mologa-jie/p/6071061.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值