• 购物车


    goods = [{"name": "电脑", "price": 1999}
             {"name": "鼠标", "price": 10},
             {"name": "游艇", "price": 20},
             {"name": "美女", "price": 998}
             ]
    dic={}
    l1=[]#购买的商品
    l2=[]#商品数量
    sum=0
    for i in goods:
        print(goods.index(i)+1, i["name"],i["price"])
    flg = True
    while flg:
        money = input("请输入资产")
        if money.upper() == "Q":
            flg = False
            continue
        elif money.isdigit() and int(money)>=0:
            flg1 = True
            while flg1:
                a = input("选择商品序号,或q退出或p返回上层")
                if a.upper()=="Q":
                    flg = False
                    flg1 = False
                    break
                elif a.upper()=="P":
                    flg = True
                    break
                elif  a.isdigit() and int(a) in range(1,len(goods)+1):
                    l1.append(a)
                    flg2 = True
                    while flg2:
                        b = input("选择购买个数,或退出或返回上一层")
                        if b.upper()=="Q":
                            flg = False
                            flg1 = False
                            break
                        elif b.upper()=="P":
                            break
                        elif b.isdigit() and int(b)>=0:
                            l2.append(b)
                            flg3 = True
                            while flg3:
                                d = input("继续购买y或结账n")
                                if d.upper()=="Y":
                                    flg2 = False
                                    break
                                elif d.upper()=="N":
                                    for f in  range(len(l1)):
                                        money1=goods[int(l1[f])-1]["price"]*int(l2[f])
                                        sum+=money1
                                    if int(money)>=sum:
                                            print("购买成功")
                                            print("花了%s,余额为%s" %(sum,int(money)-sum))
                                            for f in range(len(l1)):
                                                print("购买了%s个%s" %(l2[f],goods[int(l1[f])-1]["name"]))
                                            flg=False
                                            flg1=False
                                            flg2 = False
                                            flg3=False
                                            break
                                    else:
                                        flg4=True
                                        while flg4:
                                            print("余额不足,是否充值Y/N")
                                            cho = input("--->")
                                            if cho.upper()=="Y":
                                                flag = True
                                                while flag:
                                                    k = input("充值金额")
                                                    if k.isdigit() and int(k)>0:
                                                        money = int(money)+int(k)
                                                        flag=False
                                                        flg4=False
                                                        break
                                                    else:
                                                        print("重新输入")
                                                        continue
                                            elif cho.upper()=="N":
                                                print("欢迎再来")
                                                flg = False
                                                flg1 = False
                                                flg2 = False
                                                flg3=False
                                                flg4 = False
                                                break
                                            else:
                                                print("重新输入")
                                                continue
    
                                else:
                                    print("输入错误重新选择")
                                    continue
    
    
                        else:
                            print("输入错误,重新输入")
                            flg = False
                            flg1=False
                            continue
    
                else:
                    print("商品序号不对重新输入")
                    flg = False
                    continue
        else:
            print("输入不正确,重新输入")
  • 相关阅读:
    数据仓库_Linux(3)
    2.1(构造序对)
    要修改一万个位置的jdk版本
    8个球7个一样重的,有一个偏重,一个天平,如何两次找出偏重的小球
    玄学
    异常:java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag
    提高输入效率
    fan
    idea
    打印整数的补码
  • 原文地址:https://www.cnblogs.com/wzbk/p/8515818.html
Copyright © 2020-2023  润新知