Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

WGU Foundations of Programming (Python) (E010) Exam - Topic 3 Question 11 Discussion

Posted by Mira on Jul 19, 2026 at 04:57 AM

SIMULATION

Write a complete function password_strength(password) that returns "Strong" if the password is at least 8 characters long and contains both letters and numbers, "Weak" otherwise.

For example, password_strength("abc123def") should return "Strong".

def password_strength(password):

# TODO: Return "Strong" or "Weak" based on password criteria

if len(password) < 8:

return "Weak"

has_letter = False

has_number = False

for char in password:

if char.isalpha():

has_letter = True

elif char.isdigit():

has_number = True

# TODO: Add your return logic here based on has_letter and has_number

pass

Suggested Answer: A

==========

Step 1: First, check the password length using len(password).

Step 2: If the password has fewer than 8 characters, return 'Weak' immediately.

Step 3: Create two Boolean variables: has_letter and has_number.

Step 4: Loop through each character in the password.

Step 5: Use .isalpha() to check for letters and .isdigit() to check for numbers.

Step 6: If the password contains both at least one letter and at least one number, return 'Strong'.

Step 7: Otherwise, return 'Weak'.

Correct code:

def password_strength(password):

if len(password) < 8:

return 'Weak'

has_letter = False

has_number = False

for char in password:

if char.isalpha():

has_letter = True

elif char.isdigit():

has_number = True

if has_letter and has_number:

return 'Strong'

else:

return 'Weak'

Example:

print(password_strength('abc123def'))

print(password_strength('abcdefgh'))

print(password_strength('12345678'))

Output:

Strong

Weak

Weak


Get Premium Foundations of Programming (Python) (E010) Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
17 comments · newest first
EL
Elmer 5 days ago
Good plan! Use flags for checks.
MA
Martin 10 days ago
I’ll focus on the loop for letters and numbers.
CA
Casie 15 days ago
Exactly! Length matters.
EL
Elmer 20 days ago
But "abc123def" is "Strong"!
MA
Martin 26 days ago
I’d say "Weak" for "abc123".
CA
Casie 1 month ago
I feel confident about it. Clear criteria!
EL
Elmer 1 month ago
I think it's straightforward. Just check length and types.
MA
Martin 1 month ago
This question is tricky!
AR
Arlene 2 months ago
Wait, only letters and numbers? That seems too simple!
CO
Cortney 2 months ago
This is a good start, but I feel like it needs more checks.
WI
Wilda 2 months ago
I thought it should be at least 10 characters for strong?
IZ
Izetta 2 months ago
Definitely agree, but what about special characters?
ST
Stevie 2 months ago
Looks like a solid way to check password strength!
BI
Billye 2 months ago
I think I need to double-check how to use the `isalpha()` and `isdigit()` methods correctly in the loop.
TE
Terry 3 months ago
I feel a bit uncertain about how to handle the return logic. Do we need to check both conditions before returning?
EL
Ellsworth 3 months ago
This seems similar to that exercise where we validated usernames. I think we just need to add a return statement at the end.
GR
Gretchen 3 months ago
I remember we practiced checking for letters and numbers in strings, but I'm not sure how to combine those checks.
0/2000 characters

Save Cancel