Python 如何让代码重新运行已采用的旧路径?

Python 如何让代码重新运行已采用的旧路径?,python,python-3.x,jupyter-notebook,Python,Python 3.x,Jupyter Notebook,我正在尝试创建一个ATM,它要求用户登录一个用户名,然后每个用户都有三个单独的帐户可供选择。在这些账户中,每个账户都允许他们存款、取款和查看余额。我的问题是我不太擅长列表,我相信这就是所需要的。一旦我已经输入了代码,我就不能让代码作为新用户登录。示例:我创建一个用户Bob并登录并存款。然后我从Bob注销,想创建一个新用户Tim。当我创建Tim时,它不会让我记录它。每次我把提姆放进去,它都会给我同样的菜单 我认为我需要创建一个用户列表,然后为每个用户创建一个列表,我不知道如何做到这一点。从我的代码

我正在尝试创建一个ATM,它要求用户登录一个用户名,然后每个用户都有三个单独的帐户可供选择。在这些账户中,每个账户都允许他们存款、取款和查看余额。我的问题是我不太擅长列表,我相信这就是所需要的。一旦我已经输入了代码,我就不能让代码作为新用户登录。示例:我创建一个用户Bob并登录并存款。然后我从Bob注销,想创建一个新用户Tim。当我创建Tim时,它不会让我记录它。每次我把提姆放进去,它都会给我同样的菜单

我认为我需要创建一个用户列表,然后为每个用户创建一个列表,我不知道如何做到这一点。从我的代码中可以看出,我只是对每个帐户中的资金使用设置值。这可能是为什么主登录不允许我使用其他用户的问题吗

user_list = []
data_list = []
index = -1

user_input = 0
user_account = 0
credit_input = 0
checking_input = 0
saving_input = 0

while user_input != 3:
    print("1: Login\n2: New User\n3: Exit")
    user_input = int(input("Please pick an option: "))

    if user_input == 1:
        username = input("Login: ")
        while username not in user_list:
            username = input("No user, try again: ")
        index = user_list.index(username)
        while user_account != 4:
            print("Accounts:\n\n1: Credit\n2: Checking\n3: Savings\n4:Exit ")
            user_account = int(input("Please pick an option: "))
            if user_account == 1:
                credit_funds = 0
                while credit_input != 4:
                    print("1: Deposit")
                    print("2: Withdraw")
                    print("3: Credit Account Balance")
                    print("4: Exit") 
                    credit_input = int(input("Pick an option: "))
                    if credit_input == 1:
                        number = int(input("Deposit amount: "))
                        credit_funds += number
                        print("Deposit of $", number)
                    elif credit_input == 2:
                        number = int(input("Withdraw amount: "))
                        while number > credit_funds:
                            print("\nInsufficient Funds")
                            break
                        else:
                            credit_funds -= number
                            print("\nSuccessful Withdraw of $", number)
                    elif credit_input == 3:
                        print("Avalable balance: $", credit_funds)


            elif user_account == 2:
                checking_funds = 0
                while checking_input != 4:
                    print("1: Deposit")
                    print("2: Withdraw")
                    print("3: Checking Account Balance")
                    print("4: Exit")
                    checking_input = int(input("Pick an option: "))
                    if checking_input == 1:
                        amount = int(input("Deposit amount: "))
                        checking_funds += amount
                        print("Deposit of $", amount)
                    elif checking_input == 2:
                        amount = int(input("Withdraw amount: "))
                        while amount > checking_funds:
                            print("\nInsufficient Funds")
                            break
                        else:
                            checking_funds -= amount
                            print("\nSuccessful Withdraw of $", amount)
                    elif checking_input == 3:
                        print("Avalable balance: $", checking_funds)


            elif user_account == 3:
                saving_funds = 0
                while saving_input != 4:
                    print("1: Deposit")
                    print("2: Withdraw")
                    print("3: Saving Account Balance")
                    print("4: Exit")
                    saving_input = int(input("Pick an option: "))
                    if saving_input == 1:
                        number3 = int(input("Deposit amount: "))
                        saving_funds += number3
                        print("Deposit of $", number3)
                    elif saving_input == 2:
                        number3 = int(input("Withdraw amount: "))
                        while number3 > saving_funds:
                            print("\nInsufficient Funds")
                            break
                        else:
                            saving_funds -= number3
                            print("\nSuccessful Withdraw of $", number3)
                    elif saving_input == 3:
                        print("Avalable balance: $", saving_funds)

    elif user_input == 2:
        username = input("Please pick a username: ")
        while username in user_list:
            username = input("Pick another please: ")
        user_list.append(username)
当用户“注销”(登录时按4)时,您将
user\u account
设置为4(退出条件)。从那以后就再也没有不安定过。因此,当其他用户尝试登录时,程序将测试
user\u account!=4
,该测试失败,并且从不进入while循环(
while user\u account!=4
)。我怀疑所有其他出口条件也会发生同样的情况

我建议在采取适当措施后,将任何输入的值重置为0。或者,当达到退出条件时,使用
while True:
和显式
break

例如:

while True:
    print("1: Login\n2: New User\n3: Exit")
    user_input = int(input("Please pick an option: "))

    if user_input == 1:
        print("Option 1 selected")
        # DO SOMETHING
    elif user_input == 2:
        print("Option 2 selected")
        # DO SOMETHING
    elif user_input == 3:
        break

我希望这能起作用。

因此,从第一个选项列表中,退出选项是我用来完全结束代码的选项。这是我的错,因为在登录后,当它应该说注销时,我有选项4作为退出。用户注销后,我无法重新登录。正如你所说,我试着在两个结尾都加上一个停顿,但仍然没有成功。对不起,我知道我的代码很难遵循。对不起,我忘了修复while循环条件下使用
user\u input
导致的逻辑错误
users={};stop='r'
def login(name,users):
    if name in users.keys():
        return True
    return False
def create():
    name=input('please write your name')
    users[name]=0
def main(users):
    print('Welcome to my ATM\n')
    buff=input('SELECT one of the following:\nC)create account\nL)login')
    if(buff=='C' or buff=='c'):
        create()

    elif(buff=='L' or buff=='l'):
        name=input('name: ')
        buff2=login(name,users)
        if(buff2==False):
            print('your name is not in account list')

        elif(buff2==True):
            buff=input('SELECT:\nA)cash report\nD)delete account')   
            if(buff=='A' or buff=='a'):
                print(users[name])               
            elif(buff=='D' or buff=='d'):
                k=users.pop(name)
                print('finished! ')
while(stop=='r'):
    buff3=input("press 's' to stop ATM otherwise press enter to continue ...")
    if(buff3=='s'):
        break
    main(users)