livepython.net

239. Python Program to Check How Strong a Password Is

EasyPhase 1 · Warm-up

You know len(), for loops over text and string methods like isdigit() and lower(). That is all you need here.

Overview

Many websites show how strong your new password is while you type it. A strong password is much harder to guess.

Problem Statement

Zara builds a sign-up page. The page checks each password against 4 rules:

  1. It has 8 characters or more.
  2. It has at least one digit (0 to 9).
  3. It has at least one uppercase (capital) letter, like A.
  4. It has at least one lowercase (small) letter, like a.

The strength comes from the number of rules the password passes:

  • 0 or 1 rules: Weak
  • 2 or 3 rules: Medium
  • all 4 rules: Strong

Read the password. Print the number of rules it passes, then its strength, in this format:

Rules passed: <count>
Strength: <strength>

Steps

  1. Read the password and start a score at 0.
  2. Add 1 if the password has 8 characters or more.
  3. Loop over the characters. If any of them is a digit, add 1 (only once).
  4. Add 1 if it has an uppercase letter, and 1 if it has a lowercase letter.
  5. Print the score, then Weak, Medium or Strong.

Examples

Example 1. Input Sunny2024 gives:

Rules passed: 4
Strength: Strong

Why: it has 9 characters, the digits 2024, the uppercase S and the lowercase unny. All 4 rules pass.

Example 2. Input password gives:

Rules passed: 2
Strength: Medium

Why: it has exactly 8 characters, so rule 1 passes, and it has lowercase letters. It has no digit and no uppercase letter, so 2 rules pass.

Input

One line: the password, 1 to 30 characters, with no spaces. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

Two lines: Rules passed: <count>, then Strength: <strength>, where the strength is Weak, Medium or Strong. The tests try 6 different inputs, also passwords of 7 and 8 characters, and one that passes no rule.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 12 · Working With Strings
solution.py
# write your code here

EXPECTED OUTPUT

1Rules passed: 4
2Strength: Strong

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.