In: Computer Science
Please look at my code and in case of indentation issues check the screenshots.
---------------main.py--------------------------
#validate takes a dictionary, a username, and a password
def validate(usersDict, username, password):
if username in usersDict.keys():
#Find the given username in the dictionary
if usersDict[username] ==
password: #compare the given password with the one that
belongs to that username
return True
#Return true if password is
correct
return False
#false if password is wrong
for that username
#Create a dictionary called users containing the data given in
above table
usersDict = {'User1': '101010', 'User2' : '112121', 'User3' :
'211211', 'User4' : '312132'}
username = input("Enter a username: ")
password = input("Enter a password: ")
print(validate(usersDict, username, password)) #Call
the function and pass the users dictionary, username, password
--------------Screenshots-----------------------
------------------Output----------------------
-----------------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs
down.
Please Do comment if you need any clarification.
I will surely help you.