Password Strength Checker

Medium ⏱ 12 min 60% acceptance ★★★★★ 4.5
Write a function password_strength(pw) that rates a password string as "Weak", "Medium", or "Strong". A password is "Strong" if it has length >= 8, contains at least one digit, and at least one uppercase letter. It is "Medium" if it has length >= 8 but is missing a digit or an uppercase letter. Otherwise it is "Weak".

Examples

Example 1
Input
password_strength("Abcdef12")
Output
"Strong"
Explanation

Length 8+, has a digit and an uppercase letter.

Example 2
Input
password_strength("abcdefgh")
Output
"Medium"
Explanation

Length 8+ but no digit and no uppercase letter.

Example 3
Input
password_strength("abc")
Output
"Weak"
Explanation

Too short.

Constraints

  • pw is a non-empty string.

Topics

Conditional Statementsguard clauses

Companies

PayPalRazorpayJPMorgan Chase

Hints

Hint 1

Use `any(c.isdigit() for c in pw)` and `any(c.isupper() for c in pw)`.

Hint 2

Check length first as a guard before checking the other two conditions.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.