database={'a':'11', 'b':'22', 'c':"33", 'd':"44", 'c':'55'} username=input('input ur name:') password=input('ur password') if database[username]==password: print('log in successful') else: print('log in faliue') the program results is confusing when you typed your name 'c',then typed ur password '33',it log in failur!!!!
The reason for that is you can only have one key with a specific name in a dictionary. You have two 'c's in your dictionary, one with value '33' and one with value '55'. The way that Python takes care of this is by saying to itself "Oh...55 is the newest value, so that must be the one that they meant to use." It completely writes over the "33" with "55" which is why you're getting a login failure message.
Dictionaries are very flexible for storing data, but the basic rule for dictonaries is that they " should have" unique keys. In you code here, the database will have only 'c':55, the first 'c' value will be overwritten. remember --- dictornaries --- should have ''''''''unique keys''''''
Join our real-time social learning platform and learn together with your friends!