首页 > 解决方案 > Calling the second function in a "while" loop

问题描述

I'm on my early python self learning path and somehow I can't get the code to execute def cadastro() whenever 1 is imputed. Can you please assist. Valuable contributions have been shared with me on this forum which I'm greatly appreciative of, however I remain stuck with this code.

lista_de_usuarios = {}

print ('BEM VINDO AO BCI')
print("PARA CADASTRO PRESSIONE 1 E 2 PARA LOGIN")

while True:

    opcao_1 = input()

    if opcao_1 == '':
        print ('NADA FOI SELECIONADO, ADEUS')
        break
    elif opcao_1 == 2:
        acesso()

    elif opcao_1 == 1:
        cadastro()

    def acesso():
        print ('Insira o seu usuário')
        user = input()
        print ('insira a sua palávra chave')
        password = input()
        if user in lista_de_usuarios:
            if lista_de_usuarios[user] == password:
                print ('ACESSO LIVRE')
            else:
                print ('A senha digitada está incorrecta')
        else:
            print('Este usuário não consta em nossa base de dados')
    acesso()

    def cadastro():
        print ('Insira o seu nome')
        nome = input()
        print ('insira a sua idade')
        idade = input()
        lista_de_usuarios[nome]=idade
    cadastro()

标签: python

解决方案


你忘了"在你的数字之前添加。因为您要求用户输入并添加str(),所以他们只能输出一个字符串。

elif opcao_1 == "1":
    acesso()
elif opcao_1 == "2":
    cadastro()

推荐阅读