zoukankan      html  css  js  c++  java
  • ATM-core-src

    from interface import bank, shopping, user
    from lib import common

    user_data = {
    'name': None
    }


    def logout():
    if user_data['name']:
    print('退出成功')
    user_data['name'] = None
    else:
    print('你从来就没有登陆过')


    def login():
    '''
    登录
    :return:
    '''
    print('欢迎来到登陆界面:')
    if user_data['name']:
    print('你已经登陆过了!')
    return
    count = 0
    while True:
    name = input('用户名:')
    if name == 'q': break
    password = input('密码:')
    flag, msg = user.login_interface(name, password)
    if flag:
    user_data['name'] = name
    print(msg)
    break
    else:
    print(msg)
    count += 1
    if count == 3:
    print('失败过多已锁定')
    user.locked_interface(name)
    break


    def register():
    '''
    注册:
    :return:
    '''
    if user_data['name']:
    print('你已经登陆过了!')
    return
    print('注册:')
    while True:
    name = input('用户名:')
    if name == 'q': break
    password = input('密码:')
    conf_password = input('密码:')
    if password == conf_password:
    flag, msg = user.register_interface(name, password)
    if flag:
    print(msg)
    break
    else:
    print(msg)

    else:
    print('两次不一致')


    @common.login_auth
    def check_balance():
    '''
    查询
    :return:
    '''
    print('查询:')
    balance = bank.check_balance(user_data['name'])
    print(balance)


    @common.login_auth
    def transfer():
    '''
    转账
    :return:
    '''
    print('转账:')
    while True:
    toname = input('请输入需要转给的账户名:')
    if toname == 'q': break
    balance = input('转账金额:')
    if balance == 'q': break
    if balance.isdigit():
    balance = int(balance)
    falg, msg = bank.transfer_interface(user_data['name'], toname, balance)
    if falg:
    print(msg)
    break
    else:
    print(msg)
    else:
    print('输入非法')


    @common.login_auth
    def repay():
    '''
    还款
    :return:
    '''
    print('还款界面:')
    balance = input('请输入还款金额:')
    if balance.isdigit():
    balance = int(balance)
    flag, msg = bank.repay_interface(user_data['name'], balance)
    print(msg)
    else:
    print('必须数字')


    @common.login_auth
    def withdraw():
    '''
    还款界面
    :return:
    '''
    print('取款界面:')
    balance = input('请输入取款金额:')
    if balance.isdigit():
    balance = int(balance)
    falg, msg = bank.withdraw_interface(user_data['name'], balance)
    if falg:
    print(msg)
    else:
    print(msg)


    @common.login_auth
    def check_record():
    '''
    查看流水
    :return:
    '''
    print('查看流水:')
    flow = bank.check_record_interface(user_data['name'])
    for i in flow:
    print(i)
    # print(bank.check_record_interface(user_data['name']))


    @common.login_auth
    def shop():
    '''
    购物
    :return:
    '''
    print('购物:')
    goods = [
    ['coffee', 10],
    ['chicken', 20],
    ['iphone', 8000],
    ['macPro', 15000],
    ['car', 100000],
    ]
    shoppingcart = {}
    cost = 0
    user_balance = bank.check_balance(user_data['name'])
    while True:
    for i, j in enumerate(goods):
    print('%s:%s' % (i, j))
    choice = input('请输入购买的编码:')
    if choice.isdigit():
    choice = int(choice)
    if choice >= len(goods): continue
    goods_name = goods[choice][0]
    goods_price = goods[choice][1]
    if user_balance >= goods_price:
    if goods_name in shoppingcart:
    shoppingcart[goods_name]['count'] += 1
    else:
    shoppingcart[goods_name] = {'price': goods_price, 'count': 1}
    user_balance -= goods_price
    cost += goods_price
    else:
    print('余额不足')
    elif choice == 'q':
    if cost == 0: break
    print(shoppingcart)
    buy = input('确认购买(y/n)')
    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('输入非法')


    def check_shopping_cart():
    '''
    查看购物车
    :return:
    '''
    print(shopping.check_shoppingcart(user_data['name']))


    func_dic = {
    '1': login,
    '2': register,
    '3': check_balance,
    '4': transfer,
    '5': repay,
    '6': withdraw,
    '7': check_record,
    '8': shop,
    '9': check_shopping_cart,
    '10': logout
    }


    def run():
    while True:
    print('''
    1、登陆
    2、注册
    3、查询余额
    4、转账
    5、还款
    6、取款
    7、查看流水
    8、购物
    9、查看购物车
    10、退出登陆
    11、退出系统
    ''')
    choice = input('请输入需要选择的操作编码:')
    if choice == '11': break
    if choice in func_dic:
    func_dic[choice]()
  • 相关阅读:
    springboot访问静态资源遇到的坑
    mysql存储过程
    sharding-jdbc数据分片配置
    sharding-jdbc springboot配置
    数据库分库分表配置sharding-jdbc
    mysql数据库分库分表shardingjdbc
    angluarJs与后台交互小案例
    angluarJs与后台交互get
    DE1-soc软件实验”hello_word"
    编译到底做什么
  • 原文地址:https://www.cnblogs.com/wangcheng9418/p/9221752.html
Copyright © 2011-2022 走看看