Editor

Count the Possible Passwords

Intermediate · Write the code · from Safe Computing: Privacy, Passwords, Encryption and Phishing

From the lesson: Safe Computing: Privacy, Passwords, Encryption and Phishing

Your phone, your browser and your apps collect a steady stream of data about you, and the same data that makes them convenient can be used to track you, trick you or steal from you.

Read the lesson

Write count_possible_passwords(password) that estimates how many passwords of the same length an attacker would have to try, based on the kinds of characters it uses:

  • any lowercase letter adds 26 possible characters
  • any uppercase letter adds 26
  • any digit adds 10
  • any other character (a symbol or a space) adds 33
  • Return the total number of possible characters raised to the power of the password's length.

    count_possible_passwords("Ab1")  ->  238328     (62 ** 3)
    def count_possible_passwords(password):
    characters = 0
    # Add 26, 26, 10 or 33 for each kind of character the password uses
    return characters ** len(password)

    What Check runs

    Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.

    RunsExpected output
    print(count_possible_passwords("abc"))17576
    print(count_possible_passwords("Ab1"))238328
    print(count_possible_passwords("tiger"))11881376

    More Safe Computing exercises

    All Python exercises · 50 practice problems