Get Started

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”

View Course

Exercise instructions

  • Define the password_checker function, which should accept one argument called submission.
  • Check if password is equal to submission.
  • Add a keyword enabling the conditional printing of "Incorrect password" if password and submission 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    
____("____")

This exercise is part of the course

Intermediate Python for Developers

BeginnerSkill Level
4.6+
17 reviews

Dive into the Python ecosystem, discovering modules and packages along with how to write custom functions!

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free