I wanted to create a login program using dictionaries Write down the password for the member I made a program to check if the name is included or if the password of the member matches.
We can check the presence or absence of a name in the dictionary, but something seems to be wrong in the process of matching the member's name and password. Can you help me check if the password matches properly?
member={"A":4534,"B":2121,"C":1223,"D":2342,"E":8845}
print ("Member Only Window".")
while(True):
name=input("Please enter your name :")
if name in member:
password=input("Please enter password :")
if password==(member[name]):
print(name, welcome)
print("You have %d months left" %day[name])
break
else:
print("Password not correct")
else:
print(name), you are not a member of us
Enter your name: A
Please enter your password: 4534
The password doesn't match
Enter your own name: ㄹㅇㄴ하세요
ID ㄴㅇ 니십니다 is not our member
If you receive an input from Python as input
, the value is stored as a string.
If you perform a ==
operation on a string and an integer, it returns False
unconditionally.
Therefore, you can modify the code to replace the entered password with an integer.
member={"A":4534,"B":2121,"C":1223,"D":2342,"E":8845}
print ("Member Only Window".")
while(True):
name=input("Please enter your name :")
if name in member:
password=int(input("Please enter password :")
if password == member[name]:
print(name, welcome)
print("You have %d months left" %day[name])
break
else:
print("Password not correct")
else:
print(name), you are not a member of us
© 2024 OneMinuteCode. All rights reserved.