Building a password checker
You've seen how conditional statements can be used to check for equality. Now you have the skills to build a custom function, you'll combine these two techniques to build a function called password_checker
that compares a user's password to a submission, conditionally printing an output depending on the results.
This is a part of the course
“Intermediate Python for Developers”
Exercise instructions
- Define the
password_checker
function, which should accept one argument calledsubmission
. - Check if
password
is equal tosubmission
. - Add a keyword enabling the conditional printing of
"Incorrect password"
ifpassword
andsubmission
are different. - Call the function, passing
"NOT_VERY_SECURE_2023"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
password = "not_very_secure_2023"
# Define the password_checker function
____
# Check that the password variable and the submission match
if ____ ____ ____:
print("Successful login!")
# Otherwise, print "Incorrect password"
____:
print("Incorrect password")
# Call the function
____("____")