购物车程序

# -*- coding: utf-8 -*-
"""
Created on Mon Oct 29 13:37:55 2018
@author: Administrator

    购物车程序
        salary = 5000
        1.  iphone6s  5800
        2.  mac book    9000
        3.  coffee      32
        4.  python book    80
        5.  bicyle         1500
      >>>:1
         余额不足,-3000
      >>>:5
      已加入bicyle 到你的购物车, 当前余额:3500
      >>>:quit
      您已购买一下商品
      bicyle    1500
      coffee    30
      您的余额为:2970
      欢迎下次光临
"""
print("1:iphone6s 5800\n2:mac_book 9000\n3:coffee 32\n4:python_book 80\n5:bicyle 1500")
salary = int(input("salary:"))
iphone6s = 5800
mac_book = 9000
coffee =  32
python_book = 80
bicyle = 1500
tab= ["-","iphone6s","mac_book","coffee","python_book","bicyle"]
money = ["-","5800","9000","32","80","1500"]
car = []
carm = []
while salary > 0 :
    a = input()
    if a == "quit":
        print("您已购买以下商品:")
        for i in range(len(car)) :
            print(car[i],carm[i])
        print("您的余额为:%d 欢迎下次光临"%(salary))
        break        
    else:
        a = int(a)
        if (salary - int(money[a])) > 0 :
            a = int(a)
            car.append(tab[a])
            carm.append(money[a])
            print("已加入%s到你的购物车,当前余额:%d"%(tab[a],salary - int(money[a])))
            salary = salary - int(money[a])
        else:
            print("余额不足,%d"%(salary - int(money[a])))

 

转载于:https://www.cnblogs.com/sjk755/p/9954183.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值