栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python基础之模拟ATM 注册 、登录 、查询余额 、存款 、取款 、转账 、退卡(原代码)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python基础之模拟ATM 注册 、登录 、查询余额 、存款 、取款 、转账 、退卡(原代码)

curruent_users = None
users = [{'username': 'lili', 'password': '123456', 'banlance': 30000},
         {'username': 'tt',' password': '123478', 'banlance': 23000}]

def getmuen():
    muen='''
    ****欢迎来到WonluiuATM****
    *******操作菜单*******
    ****1、注册 2、登录 3、查询余额 4、存款 5、取款 6、转账 7、退卡**** 
  '''
    while True:
        print(muen)
        opt = input('请输入你想要选择的菜单:')
        if opt == '1':
            reg()
        elif opt == '2':
            login()
        elif opt == '3':
            search()
        elif opt == '4':
            deposit()
        elif opt == '5':
            withdrawal()
        elif opt == '6':
            tansform()
        elif opt == '7':
            print('欢迎下次光临')
            break
        else:
            print('请输入正确的数字')



def reg():
    while True:
        p = input('请输入用户名:')
        m = input("请输入密码:")
        for item in users:
            if p == item['username']:
                print('用户已存在!!')
                break
            else:
                if len(m) < 6:
                    print('密码小于6位数')
                    break
        else:
            users.append({'username': p, 'password': m, 'banlance': 3000})
            print('用户注册成功,请重新登录!!')
            return True

def login():
    while True:
        h = input('请输入用户名:')
        m = input("请输入密码:")
        for it in users:
            if it['username'] == h and it['password'] == m:
                print('用户登录成功')
                global curruent_users
                curruent_users = it
                return
        else:
            print('用户名或者密码错误!')


def search():
    if curruent_users: #代表登录成功了
        print('当前用户得余额为:', curruent_users['banlance'])
    else:
        print('请先登录在查询')

def deposit():
    if curruent_users:
        h = int(input('请输入存入的数目:'))
        if h % 100 == 0:
            curruent_users['banlance'] += h
            print("目前的金额为 ", curruent_users['banlance'])
        else:
            print('请正确的金额')
    else:
        print('请先登录在查询')
def withdrawal():
    if curruent_users:
        h = int(input('请输入取的数目:'))
        if h[-2:] == '00' and len(h) > 2:
            if curruent_users['banlance'] >= h:
              curruent_users['banlance'] -= h
            else:
                print('余额不足')
        else:
            print('请存取100的整数')
    else:
        print('请先登录在查询')

def tansform():
    if curruent_users:
        h = input('请输入转账的账户名称')
        if curruent_users['username'] == h:
            print("不能给自己转账")
        else:
            for item in users:
                if item['username'] == h:
                    f = input("请输入转账的金额")
                    if h[-2:] == '00' and len(h) > 2:
                        if curruent_users['banlance'] >= int(h):
                            curruent_users['banlance'] -= int(h)
                            curruent_users['banlance'] -= int(f)
                            item['banlance'] += int(f)
                        else:
                            print('余额不足')
                    else:
                        print('输入的金额有误')
                        break
                else:
                    print('请输入正确的账户')
    else:
        print('请先登录在查询')

getmuen()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/725425.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号