Learn Regular Expressions by Building a Password Generator - Step 56

I have called the len() function with re.findall(pattern, password) as the argument. I still get an error.

Your code so far

import re
import secrets
import string

def generate_password(length, nums, special_chars, uppercase, lowercase):
    # Define the possible characters for the password
    letters = string.ascii_letters
    digits = string.digits
    symbols = string.punctuation

    # Combine all characters
    all_characters = letters + digits + symbols

    while True:
        password = ''
        # Generate password
        for _ in range(length):
            password += secrets.choice(all_characters)
        constraints = [
            (nums, r'\d'),
            (lowercase, r'[a-z]'),
            (uppercase, r'[A-Z]'),            
            (special_chars, fr'[{symbols}]')            

/* User Editable Region */

        # Check constraints
        for constraint, pattern in constraints:
        len(re.findall(pattern, password))

/* User Editable Region */

  )  return password

# new_password = generate_password(8)
# print(new_password)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 56

Hello zack,

It looks like you changed the indentation, your len call is now no longer in the for loop. Once you adjust that it should work as intended.

@HungryBee, thanks for your help. I have pushed and shoved the len() call each and every way. I have indented by 4 spaces, 8 spaces, 16 spaces and every other combination in between. I still get sorry your code doesn’t pass

Assuming your code still looks like the first post, just add 1 more tab in front of the len method to make it match with the for loop.

Otherwise, could you could try and reset the step and start fresh.

the len function needs to be indented 4 more spaces so to be inside the loop

Wait it looks like there’s also a round bracket after the “Editable Region” that isn’t supposed to be there. I’m not sure what happened, but you may just wanna reset and redo it.

1 Like

Hah!!!. Thanks once again @HungryBee. I reset the question tabbed and voila!

1 Like

Yay I’m very glad! You got this!!! :blush:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.