简体   繁体   English

银行ATM登录Python

[英]Bank ATM Login in Python

This is an ATM program with basic functions.这是一个具有基本功能的ATM程序。 After new user registration, the user is able to proceed to the login function and bank operations after.新用户注册后,用户可以进行登录function和银行操作。 However, existing users can't proceed to bank operations after login as the program just stops running.但是,现有用户在登录后无法继续进行银行操作,因为程序刚刚停止运行。 How can I fix that?我该如何解决?

.....
def init():
    print('Welcome to Esther Bank')
    
    have_account = int(input('Do you have an account with us? \n 1 (yes) 2 (no) \n'))

    if(have_account == 1):
        login()
    elif(have_account == 2):
        register()
    else:
        print('You have selected an invalid option')
        init()


#user login
def login():
    print('***Login to your account***')

    user_acct = int(input('Enter your account number: \n'))
    user_pwd = input('Enter your password: \n')

    for acct_no, user in database.items():
        if user_acct == acct_no:
            if user_pwd == user[3]:
                bank_operations(user)
        else: 
            print('Invalid account or password, try again')
            login()

#user registration
def register():
    print('********Register******')
    email = input('Enter your email address: \n')
    f_name = input('Enter your first name: \n')
    l_name = input('Enter your last name: \n')
    password = input('Create a strong password: \n') 

    account_number = generate_acct_number()
    balance = 0

    database[account_number] = [f_name, l_name, email, password, balance]
    
    print('Welcome %s, your account has been created \n' %f_name)
    print('Your account number is %s \n' %account_number)
    print('Ensure your keep your account number and password safe')
    login()


#bank operations
def bank_operations(user):
    print('Welcome %s %s' %(user[0], user[1]))
    print('What would you like to do? \n')
    print('1. Deposit')
    
.....

This is how I would redefine Your login function:这就是我将如何重新定义您的登录 function:

def login():
    print('***Login to your account***')

    user_acct = int(input('Enter your account number: \n'))
    user_pwd = input('Enter your password: \n')

    if user_acct not in database.keys():
        print('Invalid account or password, try again')
        login()
        return

    if database[user_acct][3] == user_pwd:
        bank_operations(database[user_acct])
    else:
        print('Invalid account or password, try again')
        login()
        return

first check if the user actually is in the database and if not call the function again and stop the current one, if the user is in database just check if passwords match首先检查用户是否真的在数据库中,如果没有再次调用 function 并停止当前用户,如果用户在数据库中,只需检查密码是否匹配

EDIT: made some more improvements编辑:做了更多的改进

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM