Answer to Question #312624 in Python for Chetan mirje

Question #312624

Given the following student data:



image



Write a Python code to print('Welcome student name') if both username and password entered by user match for that student. Note: Check first username and then password



Input Format



Username: 122



Password: Ghi122



Constraints



i) If entered username is not present in the list of usernames, then print Enter a valid username



ii) If entered password is not present in the list of passwords, then print Password Incorrect



iii) If both username and password belong to the same student, then print Welcome student_name



iv) If username and password do not belong to the same student, then print Username and password do not match



Output Format



Output: Welcome Ghi

1
Expert's answer
2022-03-16T10:23:19-0400
for i in range(3):
    username = input("Enter username: ")
    password = input("Enter password: ")

    if username == "122":
        if password == "Ghi122":
            print("Welcome " + username)
            break
        else:
            print("\nPassword incorrect")
            print("Try Again!\n")
    else:
        print("\nUsername incorrect")
        print("Try Again!\n")
else:
    print("No more attemps!")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS