首页 > 其他 > 详细

购物车

时间:2020-07-06 13:31:12      阅读:48      评论:0      收藏:0      [点我收藏+]
# 1、启动程序后,让用户输入工资,然后进入循环,打印商品列表和编号
# 2、允许用户根据商品编号选择商品
# 3、用户选择商品后,检测余额是否够,够就直接扣款,并加入购物车, 不够就提醒余额不足
# 4、可随时退出,退出时,打印已购买商品和余额
# -*- encoding: utf-8 -*-
goods = [
{"name": "电脑", "price": 1999},
{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998}
]
money = input(total money:).strip()
while not money.isdigit():
    print(input error! )
    money = input(total money:).strip()
money = int(money)
for i in enumerate(goods):
    print(i)
flag = True
shop_list = []
cost = 0
res = money
while flag:
    shops_add = input(select one thing:).strip()
    if shops_add.isdigit():
        if int(shops_add) in range(len(goods)):
            print(type(goods[int(shops_add)][name]))
            shop_list.append(goods[int(shops_add)][name])
            cost += goods[int(shops_add)][price]
            res = money - cost
            if res < 0:
                flag = False
                print(余额不足)
        else:
            print(no select thing in the shop list!)
    elif shops_add.upper() == Q:
        flag = False
        print(you have bought these things:{0},your res is {1}.format(shop_list,res))

 

购物车

原文:https://www.cnblogs.com/thanos-ryan/p/13254236.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!