Password Strength Checker with Keyword Rules

Medium ⏱ 12 min 47% acceptance ★★★★☆ 4.4
Write a function password_strength(password) that returns "Strong" if the password is at least 8 characters long AND contains at least one digit AND at least one uppercase letter; returns "Medium" if it is at least 8 characters but is missing a digit or an uppercase letter (but not both missing); and returns "Weak" otherwise.

Examples

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

Length >= 8, has a digit (1,2) and an uppercase letter (A).

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

Length is fine but both digit and uppercase are missing, so it does not qualify as Medium.

Example 3
Input
password_strength("Abcdefgh")
Output
Medium
Explanation

Length >= 8 and has uppercase, but no digit -- exactly one requirement missing.

Constraints

  • password is a non-empty string.

Topics

Functionsinput validation

Companies

PayPalRazorpayAdobe

Hints

Hint 1

Use any(ch.isdigit() for ch in password) and any(ch.isupper() for ch in password).

Hint 2

Count how many of the two extra conditions (digit, uppercase) are satisfied, then branch on length and that count.

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