Start learning free

LESSON 164 OF 410 · PROJECTS: EVERYDAY PROGRAMS

Password Strength V1 - Length Check in Python

Practice

A tiny password strength checker that looks only at the length of the password.

You start with:

password = "Secret99"

Build:

Password length: 8
OK

Rules:

  • Collect the output lines in a variable named receipt: one string with the lines joined by "\n" (for example build a list lines and join it). The grader prints receipt for you, so do not call print.
  • Add the line "Password length: " followed by the number of characters.
  • If the length is at least 8, add the line OK; otherwise add the line Too short.

Try other passwords: with abc the output is

Password length: 3
Too short

Use len(password) to get the length and str(...) to concatenate it with a string.

password = "Secret99"

length = len(password)
lines = []
lines.append("Password length: " + str(length))
if length >= 8:
    lines.append("OK")
else:
    lines.append("Too short")
receipt = "\n".join(lines)

STEP 1 OF 6
    Ctrl + Enter to check

    Password Strength V1 in Python

    Keep going with PythonAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free