import getpass
user = str(input('Usuário: ')) # user é variavel global
def login(): # user não existe dentro de login()
while(user!='admin'):
user = str(input('Usuário: ')) # essa linha deveria estar identada pra ficar dentro do loop while
if (user=='admin'):
passwd = getpass.getpass('Senha: ')
else:
login()
I made some punctual comments in your original code, below is the code I imagine you tried to make.
import getpass
user = str(input('Usuário: '))
def login(user): # user passado por parametro pra poder ser acessado dentro da função
while(user!='admin'):
user = str(input('Usuário: ')) # informação dentro do loop while identada corretamente
if (user=='admin'):
passwd = getpass.getpass('Senha: ')
else:
login(user) # variavel user sendo passada por parametro pra função login.
passwd = getpass.getpass('Senha: ') # recebe passwd após sair da função
I imagine the end result would be this. Note that if the goal is to print the string on the screen Senha:
before the user enters the password, you will have to do something like @Sidon did, because the getpass.getpass function does not print the string passed by parameter.
Your code repeats Password: twice after it is typed the user and enter keyboard, but it was very interesting. I will give a studied!
– Uondaime
I did so because on some consoles getpass is "invisible", including where I posted the code.
– Sidon