Learn Regular Expressions by Building a Password Generator - Step 59

not sure what I’m missing :smiling_face_with_tear:

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
        count = 0
        if constraint <= len(re.findall(pattern, password)):
        count += 1  

# User Editable Region

    return password

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 59

Hi, welcome to the forum!

Where did the for loop go?

Also need to check your indentation in the if statement

if b > a:
  print("b is greater than a")

You are so close. The question is slightly misleading. It should read

Use the expression you wrote in the previous step as the condition of an if statement inside the for loop.

I did so but its still not running :melting_face:

Check constraints

    count = 0
    for constraint, pattern in constraints:
        if constraint <= len(re.findall(pattern, password)):count += 1 

its telling me " You should increment count by one inside your new if statement." but I thought I did so

Use this syntax and indentation for your if statement:

if <condition>:
    <code block>

if b > a:
  print("b is greater than a")

You can review it here:

1 Like

:dizzy_face: :dizzy_face: took me a few tries to realize my “count += 1” should be in the body of my if.

Thank you for the help!!