Q. Write a program that uses a dictionary that contains ten usernames and passwords. The program should ask the user to enter their usernames and passwords. If the username is not in the dictionary, the program should indicate that the person is not a valid user of the system. If the username is in the dictionary, but the user does not enter the right password, the program should say that the password is invalid. If the password is correct, then the program should tell the user that they are now logged into the system.

 

Answer = 

 

dic = {'Path' : "2003",
       'walla' : "1809",
       'Portal' : "1912",
       'Express' : "2003",
       'Computer' : "9834",
       'Python' : "1990",
       'Mysql' : "2001",
       'c++' : "1996",
       'java' : "1998",
       'html' : "1999" }

username = input("Enter username :- ")

if username in dic :
    password = input("Enter password :- ")
    if dic[username] == password :
        print ("You are now logged into the system.")
    else :
        print ("Invalid password.")
else :
    print ("You are not valid user.")

 

Output :- 

Enter username :- Path
Enter password :- 2003
You are now logged into the system.
>>> 

Enter username :- walla
Enter password :- 1234
Invalid password.
>>> 

Enter username :- temp
You are not valid user.
>>>

12 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post