예제 #1
0
def shop():
    '''
    1 先循环打印出商品
    2 用户输入数字选择商品(判断是否是数字,判断输入的数字是否在范围内)
    3 取出商品名,商品价格
    4 判断用户余额是否大于商品价格
    5 余额大于商品价格时,判断此商品是否在购物车里
        5.1 在购物车里,个数加1
        5.1 不在购物车里,拼出字典放入({‘good’:{‘price’:10,‘count’:1}})
    6 用户余额减掉商品价格
    7 花费加上商品价格
    8 当输入 q时,购买商品
        8.1 消费为0 ,直接退出
        8.2 打印购物车
        8.3 接受用户输入,是否购买 当输入y,直接调购物接口实现购物
    :return:
    '''
    print('购物')
    goods_list = [['coffee', 10], ['chicken', 20], ['iphone', 8000],
                  ['macPro', 15000], ['car', 100000]]
    shoppingcart = {}
    # {‘coffee’:{‘price’:10,‘count’:2},‘car’:{‘price’:10000,‘count’:1}}
    cost = 0
    user_balance = bank.check_balance_interface(user_data['name'])
    while True:
        for i, good in enumerate(goods_list):
            print('%s : %s ' % (i, good))
        choice = input('请输入要购买的商品(数字)(q退出并购买):').strip()
        if choice.isdigit():
            choice = int(choice)
            if choice >= len(goods_list): continue
            good_name = goods_list[choice][0]
            good_price = goods_list[choice][1]
            if user_balance >= good_price:
                if good_name in shoppingcart:
                    shoppingcart[good_name]['count'] += 1
                else:
                    shoppingcart[good_name] = {'price': good_price, 'count': 1}
                user_balance -= good_price
                cost += good_price
            else:
                print('余额不足')
        elif choice == 'q':
            if cost == 0: break
            print(shoppingcart)
            buy = input('确认购买吗?(y/n)').strip()
            if buy == 'y':
                flg, msg = shopping.shopping_interface(user_data['name'], cost,
                                                       shoppingcart)
                if flg:
                    print(msg)
                    break
                else:
                    print(msg)

            else:
                print('您没买东西')
                break
        else:
            print('输入非法')
예제 #2
0
def check_balance():
    """
    查看余额
    """
    print('---------\n查看余额\n---------\n')
    balance = bank.check_balance_interface(user_dic['user_name'])
    print(f'尊敬的用户您好,您的余额为:{balance}')
예제 #3
0
파일: src.py 프로젝트: shx-1999/ATM
def check_balance():
    '''
    查看余额.
    :return:
    '''
    print('查看余额。。。')
    balance = bank.check_balance_interface(user_data['name'])
    print(balance)
예제 #4
0
def shopping():
    print('欢迎来到购物界面')
    goods_list = [['电脑', 5000], ['手机', 2388], ['手表', 13888], ['沙茶面', 20],
                  ['冰红茶', 3.5]]

    shop_car = {}
    cost = 0

    balance = bank.check_balance_interface(user_info['user'])

    while True:
        for index, goods in enumerate(goods_list):
            print(index, goods)

        choice = input('请输入商品编号,输入q退出:').strip()
        if choice == 'q':
            break
        if not choice.isdigit():
            print('请输入商品编号')
            continue

        choice = int(choice)

        goods_name, goods_price = goods_list[choice]

        if balance >= goods_price:
            if goods_name in shop_car:
                shop_car[goods_name] += 1
            else:
                shop_car[goods_name] = 1

            cost += goods_price
        else:
            print('账户余额不足')

    if not cost:
        print('未选择商品')
        return

    sure = input('购买输入y,存入购物车输入n:').strip()
    if sure == 'y':
        flag, msg = shop.shop_pay_interface(user_info['user'], shop_car, cost)
        if flag:
            print(msg)
        else:
            print(msg)
    elif sure == 'n':
        flag, msg = shop.shopping_car_interface(user_info['user'], shop_car)
        if flag:
            print(msg)
        else:
            print(msg)
예제 #5
0
def clean_shop_cart():
    balance = bank.check_balance_interface(user_info['name'])
    while 1:
        choice = input('是否要清空当前的购物车:>>(y/n) -->').strip()
        if choice == 'y':
            money_num = shop.clean_shop_cart_interface(user_info['name'])
            if (balance + setting.CREDIT_MONEY) >= money_num:
                flag, msg = bank.clean_shop_cart_interface(
                    user_info['name'], money_num)
                if flag:
                    print(msg)
                    break
            else:
                print('当前余额不支持此次付款...')
        elif choice == 'n':
            break
    pass
예제 #6
0
def shop():
    user_balance = bank.check_balance_interface(user_info['name'])
    cost = 0
    shopping_cart = {}
    good_list = [['coffee', 10], ['chicken', 20], ['iphone', 8000],
                 ['macPro', 15000], ['car', 100000]]
    while True:
        for i, good in enumerate(good_list):
            print("%s:%s" % (i, good))
        choice = input("请输入人你需要购买的商品:").strip()
        if choice.isdigit():
            choice = int(choice)
            if choice > len(good_list): continue
            good_name = good_list[choice][0]
            good_price = good_list[choice][1]
            if user_balance >= good_price:
                if good_name in shopping_cart:
                    shopping_cart[good_name]['count'] += 1
                else:
                    shopping_cart[good_name] = {
                        'price': good_price,
                        'count': 1
                    }
                print("您成功将[%s]加入了购物车" % good_name)
                user_balance -= good_price
                cost += good_price
        if choice == 'q':
            if cost == 0:
                break
            print(shopping_cart)
            config = input("你确定购买完成了,开始结账吗?(y/n):").strip()
            if config == 'y':
                flag, msg = shopping.shooping_interface(
                    user_info['name'], cost, shopping_cart)
                if flag:
                    print(msg)
                    break
                else:
                    print(msg)
                    break
            else:
                print("您什么都没买")
                break
예제 #7
0
def check_balance():
    print("查看余额")
    balance = bank.check_balance_interface(user_info['name'])
    print("您的余额为%s" % balance)
예제 #8
0
def check_balance():
    print('查看余额')
    balance = bank.check_balance_interface(user_info['name'])
    print('您的余额为:%s' % balance)
예제 #9
0
def shop():
    '''
    1 先循环打印出商品
    2 用户输入数字选择商品(判断是否是数字,判断输入的数字是否在范围内)
    3 取出商品名,商品价格
    4 判断用户余额是否大于商品价格
    5 余额大于商品价格时,判断此商品是否在购物车里
        5.1 在购物车里,个数加1
        5.1 不在购物车里,拼出字典放入({‘car’:{‘price’:1000,‘count’:2},‘iphone’:{‘price’:10,‘count’:1}})
    6 用户余额减掉商品价格
    7 花费加上商品价格
    8 当输入 q时,购买商品
        8.1 消费为0 ,直接退出
        8.2 打印购物车
        8.3 接受用户输入,是否购买 当输入y,直接调购物接口实现购物
    :return:
    '''
    print('购物')
    goods_list = [
        ['coffee', 10],
        ['chicken', 20],
        ['iphone', 8000],
        ['macPro', 15000],
        ['car', 100000]
    ]
    cost = 0
    shoppingcar = {}
    user_balance = bank.check_balance_interface(user_info['name'])

    while True:
        for i, k in enumerate(goods_list):
            print('%s:%s' % (i, k))
        choice = input('请输入购买的商品序号(输入q结算):').strip()
        if choice.isdigit():
            choice = int(choice)
            if choice < len(goods_list):
                good_name = goods_list[choice][0]
                good_price = goods_list[choice][1]
                if user_balance >= good_price:
                    if good_name in shoppingcar:
                        shoppingcar[good_name]['count'] += 1
                    else:
                        shoppingcar[good_name] = {'price': good_price, 'count': 1}
                    user_balance -= good_price
                    cost += good_price


                else:
                    print('余额不足!')

            else:
                print('输入越界,请重新输入!')

        elif choice == 'q':
            if cost == 0:
                print('未购买商品!')
                break
            choice_bool = input('确认购买(y/n)?')
            if choice_bool == 'y':
                flag, msg = shopping.shopping_interface(user_info['name'], cost, shoppingcar)
                if flag:
                    print(msg)
                    break
                else:
                    print(msg)
                    break


            elif choice_bool == 'n':
                print('取消购买!')
                break
            else:
                print('请输入y/n !')


        else:
            print('输入非法请重新输入!')
예제 #10
0
def check_balance():
    print("check the balance")
    balance = bank.check_balance_interface(user_data["name"])
    print(balance)
예제 #11
0
def shop():

    print("shopping")

    goods = [["coffee", 20],
             ["chicken", 20],
             ["iphone", 8000],
             ["macpro", 15000],
             ["car", 100000]]

    for i, good in enumerate(goods):
        print(i, good[0] + ":" + str(good[1]) + "$")\


    shopping_cart = {}
    user_balance = bank.check_balance_interface(user_data["name"])
    cost = 0

    while True:
        choice = input("please input the number you want to buy").strip()
        if choice.isdigit():
            choice = int(choice)

            good_name = goods[choice][0]
            good_price = goods[choice][1]

            if user_balance >= good_price:

                if good_name not in shopping_cart:
                    shopping_cart.update({good_name: {"price": good_price, "count": 1}})

                else:
                    shopping_cart[good_name]["count"] += 1
                user_balance -= good_price
                cost += good_price

            else:
                print("money is not enouth")

        elif choice == 'q':
            if cost == 0:
                break
            print(shopping_cart)

            buy = input("do you want to buy y/n").strip()

            if buy == 'y':
                flg, msg = shopping.shopping_interface(user_data["name"], cost, shopping_cart)

                if flg:
                    print(msg)
                    break

                else:
                    print(msg)
                    break

            else:
                print("you dont buy anything")
                break
        else:
            print("illegality input")
예제 #12
0
def shop():
    '''
    1 先循环打印出商品
    2 用户输入数字选择商品(判断是否是数字,判断输入的数字是否在范围内)
    3 取出商品名,商品价格
    4 判断用户余额是否大于商品价格
    5 余额大于商品价格时,判断此商品是否在购物车里
        5.1 在购物车里,个数加1
        5.1 不在购物车里,拼出字典放入({‘good’:{‘price’:10,‘count’:1}})
    6 用户余额减掉商品价格
    7 花费加上商品价格
    8 当输入 q时,购买商品
        8.1 消费为0 ,直接退出
        8.2 打印购物车
        8.3 接受用户输入,是否购买 当输入y,直接调购物接口实现购物
    :return:
    '''

    print("shop")
    good_list = [["coffee", 20],
                 ["chicken", 20],
                 ["iphone", 8000],
                 ["macPro", 15000],
                 ["car", 1000000]]

    shoppingcart = {}

    cost = 0
    user_balance = bank.check_balance_interface(user_data["name"])
    while True:
        for i, good in enumerate(good_list):
            print("%s: %s" % (i, good))
        choice = input("please input the number of the good you want to buy").strip()

        if choice.isdigit():
            choice = int(choice)
            if choice >= len(good_list):
                continue
            good_name = good_list[choice][0]
            good_price = good_list[choice][1]

            if user_balance >= good_price:
                if good_name in shoppingcart:
                    shoppingcart[good_name]["count"] += 1
                else:
                    shoppingcart[good_name] = {"price": good_price, "count": 1}
                user_balance -= good_price
                cost += good_price
            else:
                print("money is not enouth")
        elif choice == 'q':
            if cost == 0:
                break
            print(shoppingcart)
            buy = input("do you want to buy?y/n").strip()

            if buy == "y":
                flg, msg = shopping.shopping_interface(user_data["name"], cost, shoppingcart)

                if flg:
                    print(msg)
                    break
                else:
                    print(msg)


            else:
                print("you dont buy anything")
                break

        else:
            print("illegality input")
예제 #13
0
파일: src.py 프로젝트: sanqiansi/yangbin
def shop():
    """
    1.先循环打印出商品
    2.用户输入数字选择商品(判断是否是数字,判断输入的数字是否在范围内)
    3.取出商品名,商品价格
    4.判断用户余额是否大于商品价格
    5.余额大于商品价格时,判断此商品是否在购物车里
        在购物车里,个数加1
        不在购物车里,拼出字典放入({’good':{'price':10,'count':1}})
    6.用户余额减掉商品价格
    7.花费加上商品价格
    8.当输入q时,购买商品
        8.1 消费为0,直接退出
        8.2 打印购物车
        8.3 接受用户输入,是否购买 当输入y,直接调购物车接口实现购物
    :return:
    """
    print('购物')
    user_balance = bank.check_balance_interface(user_info['name'])
    cost = 0
    shopping_cart = {}
    goods_list = [
        ['coffee', 10],
        ['chicken', 50],
        ['iphone', 5000],
        ['car', 10000],
    ]
    while True:
        for i, good in enumerate(goods_list):  #enumerate把金额迭代对象生成索引
            print('%s:%s' % (i, good))
        choice = input('请选择要购买的商品:').strip()
        if choice.isdigit():
            choice = int(choice)
            if choice > len(goods_list): continue
            good_name = goods_list[choice][0]
            good_price = goods_list[choice][1]
            if user_balance >= good_price:
                if good_name in shopping_cart:
                    shopping_cart[good_name]['count'] += 1
                else:
                    shopping_cart[good_name] = {
                        'price': good_price,
                        'count': 1
                    }
                user_balance -= good_price
                cost += good_price
        if choice == 'q':
            if cost == 0:
                break
            print(shopping_cart)
            config = input('您确定购买吗?(y/n)').strip()
            if config.upper() == 'Y':
                flag, msg = shopping.shopping_interface(
                    user_info['name'], cost, shopping_cart)
                if flag:
                    print(msg)
                    break
                else:
                    print(msg)
                    break
            else:
                print('您什么都没买')
                break
예제 #14
0
파일: src.py 프로젝트: TankJam/ATM
def shopping():
    '''
            购物车
            1 先循环打印出商品
            2 用户输入数字选择商品(判断是否是数字,判断输入的数字是否在范围内)
            3 取出商品名,商品价格
            4 判断用户余额是否大于商品价格
            5 余额大于商品价格时,判断此商品是否在购物车里
                5.1 在购物车里,个数加1
                5.1 不在购物车里,拼出字典放入({‘car’:{‘price’:1000,‘count’:2},‘iphone’:{‘price’:10,‘count’:1}})
            6 用户余额减掉商品价格
            7 花费加上商品价格
            8 当输入 q时,购买商品
                8.1 消费为0 ,直接退出
                8.2 打印购物车
                8.3 接受用户输入,是否购买 当输入y,直接调购物接口实现购物
            9 商品列表
                goods_list = [
                    ['凤爪', 50],
                    ['T-shirt', 150],
                    ['macbook', 21800],
                    ['iphoneX', 7000]
                ]
            :return:
            '''
    goods_list = [['凤爪', 50], ['T-shirt', 150], ['macbook', 21800],
                  ['iphoneX', 7000]]

    # 购物车
    shopping_cart = {}

    # 初始总额
    cost = 0

    # 获取用户余额
    user_balance = bank.check_balance_interface(user_info['name'])

    while True:
        for index, goods in enumerate(goods_list):
            print(index, goods)

        choice = input('请选择商品编号: ').strip()

        if choice.isdigit():
            choice = int(choice)

            if choice >= 0 and choice < len(goods_list):

                # 商品的名称和价格
                good_name, good_price = goods_list[choice]

                if user_balance >= good_price:

                    if good_name in shopping_cart:
                        shopping_cart[good_name] += 1

                    else:
                        shopping_cart[good_name] = 1

                    cost += good_price

                    flag, msg = shop.add_shopping_cart_interface(
                        user_info['name'], shopping_cart)
                    if flag:
                        print(msg)
                        print(shopping_cart)
                else:
                    print('*穷*,请充值!')

        elif choice == 'q':
            if cost == 0: break

            confirm = input('确认购买输入 y/n 取消:').strip()

            # 输入y选择购买商品
            if confirm == 'y':
                flag, msg = bank.pay_interface(user_info['name'], cost)
                if flag:
                    print(msg)
                    break

                else:
                    print(msg)

            else:
                print('退出购买!')
                break
        else:
            print('输入有误!')
예제 #15
0
def check_balance():
    print('当前余额为:%s' % bank.check_balance_interface(user_info['name']))
예제 #16
0
def check_balance():
    print('查看余额界面')
    msg = bank.check_balance_interface(user_info['user'])
    print(msg)
예제 #17
0
파일: src.py 프로젝트: shx-1999/ATM
def shop():
    '''
    1 先循环打印出商品
    2 用户输入数字选择商品(判断是否是数字,判断输入的数字是否在范围内)
    3 取出商品名,商品价格
    4 判断用户余额是否大于商品价格
    5 余额大于商品价格时,判断此商品是否在购物车里
        5.1 在购物车里,个数加1
        5.1 不在购物车里,拼出字典放入({‘good’:{‘price’:10,‘count’:1}})
    6 用户余额减掉商品价格
    7 花费加上商品价格
    8 当输入 q时,购买商品
        8.1 消费为0 ,直接退出
        8.2 打印购物车
        8.3 接受用户输入,是否购买 当输入y,直接调购物接口实现购物
    :return:
    '''
    print('购物。。。')
    goods_list = [
        ['coffee', 10],
        ['chicken', 20],
        ['iphone', 8000],
        ['macPro', 15000],
        ['car', 100000]
    ]
    money = 0
    user_balance = bank.check_balance_interface(user_data['name'])
    shopping_cart = {}
    while True:
        for i, v in enumerate(goods_list):
            print(f'{i}: {v}')
        choice = input('请输入需要购买商品的编号(数字)(q退出)>>:').strip()
        if choice.isdigit():
            choice = int(choice)
            if choice >= len(goods_list):
                print('商品不存在')
                continue
            shop_name = goods_list[choice][0]
            shop_price = goods_list[choice][1]
            if user_balance >= shop_price:
                if shop_name in shopping_cart:
                    shopping_cart[shop_name]['count'] += 1
                else:
                    shopping_cart[shop_name] = {'price': shop_price, 'count': 1}
                user_balance -= shop_price
                money += shop_price
                print(f'{shop_name}已加入购物车')
            else:
                print('余额不足')
                continue
        elif choice.lower() == 'q':
            if money == 0:
                break
            print(shopping_cart)
            user = input('是否购买Y/N>>:').strip()
            if user.lower() == 'y':
                falg, msg = shopping.shopping_interface(user_data['name'], money, shopping_cart)
                if falg:
                    print(msg)
                    break
                else:
                    print(msg)
                    break
            elif user.lower() == 'n':
                print('你什么都没有购买')
                break
            else:
                print('无选项')
                continue

        else:
            print('输入非法字符')
예제 #18
0
def check_balance():
    print('查看余额')
    balance = bank.check_balance_interface(user_data['name'])
    print(balance)
예제 #19
0
def check_balance():
    print('查看余额界面'.center(20, '-'))
    msg = bank.check_balance_interface(user_info['name'])
    print('用户[%s]当前余额为[%s¥]' % (user_info['name'], msg))