Python写一个 简单的 购物车流程 纯用list

# -*- coding:utf-8 -*-
# __author__ : poetl
# date: 2017/12/26
salary = int(input("Please input your salary:"))
balance = salary
shop_list = [5800, 1500, 9000, 32, 80]
shop_name = ["iphone6s", "bicyle", "macbook", "coffee", "python_book"]
iphone6s = 5800
bicyle = 1500
macbook = 9000
coffee = 32
python_book = 80
all = []
msg = '''
余额: %d
--------------
list:
1.iphone6s:%d
2.bicyle:%d
3.macbook:%d
4.coffee:%d
5.python_book:%d 
-------------- ''' % (salary, iphone6s, bicyle, macbook, coffee, python_book)
print(msg)
try:
    while True:
        input_code_1 = input("选择商品  退出输入quit:")
        if input_code_1 != "quit":

            input_code = int(input_code_1) - 1
            price = shop_list[input_code]
            if balance < price:
                print("您的余额不足",balance - price)
            else:
                balance = balance - price
                print("余额为%d" % balance)
                all.append(shop_name[input_code])
                print(all)

        else:
            print('购买清单 ',all)
            print('余额 %d, 欢迎下次光临' % balance)
            break
except IndexError:
    print("你在干嘛!")

 

转载于:https://www.cnblogs.com/poetl/articles/8120700.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值