System Login - Py error

Asked

Viewed 25 times

0

I am new to the world of technology, I work more with HTML and CSS and for pleasure, I study Python. I was trying to do a simple check, but it involved functions. (for study)

Where the error appears to me and I can’t understand the problem

def login():
  print('Vamos realizar o login ...')
  user = str(input('Login: '))
  password = str(input('Password: '))
  if user == 'admin' and password == 123:
    print('Login feito com sucesso')
    menu()
  else:
    print('Login e senha incorretos, tente novamente')
    login()
      
    
def menu():
  print('Bem vindo(a) ao menu do sistema')
  opcao_inicial = str(input('[1] - Login\n[2] - Sair'))
  if (opcao_inicial == 1):
    print('Indo para o Login ...')
    login()
  elif (opcao_inicial == 2):
    print('Finalizando sistema')
  else:
    print('Valor invalido, escolha a opção novamente')
    menu()

print('Ola, seja bem vindo ao sistema')
login()

Where I put the data correctly but it only gives me the condition that has the password or incorrect login.

1 answer

0


Note that in function login() you say password is a string, but in if you compare as a number:

password = str(input('Password: '))
if user == 'admin' and password == 123:

To solve the problem just compare the password as string:

if user == 'admin' and password == '123':
  • 1

    That’s right, I was so attentive to the concept, that I always make mistakes in these silly mistakes, that make total difference, thank you. I will pay more attention

Browser other questions tagged

You are not signed in. Login or sign up in order to post.