I tell you the idea. I've been trying to login with dictionaries inside a dictionary for 2 days but I still can't find the way. The idea is to do it from the username and password that the user enters. I'm sure it's the easiest but I'm still learning xdd, I hope you can help me, thank you very much :D
usuarios = {
"iperurena": {
"nombre": "Iñaki",
"apellido": "Perurena",
"password": "123123"
},
"fmuguruza": {
"nombre": "Fermín",
"apellido": "Muguruza",
"password": "654321"
},
"aolaizola": {
"nombre": "Aimar",
"apellido": "Olaizola",
"password": "123456"
}
}
User = print(input("Escriba su usuario: "))
Pass = print(input("Escriba su password: "))
for clave in usuarios:
if User in usuarios.keys() and Pass in usuarios.values():
print("si")
else:
print("no")
Various errors:
With
input()
you get the name, and pass it toprint
. This prints it and does not return anything and thereforeUser
remains inNone
There is no point in looping through the list of users; you already have it in
User
.The part where you compare
Pass
is wrong. The expressionusuarios.values()
returns a list. This list contains all dictionaries:What you need is to retrieve the field
password
from the dictionaryusuarios[User]
.Recommendation: use
print()
inside the code to check that you are getting what you want (or use debug, whichever is more comfortable).This is the correct code: