Back to Freecodecamp

Step 64

curriculum/challenges/english/blocks/learn-regular-expressions-by-building-a-password-generator/657733bc97eb83efdb7e3988.md

latest1.4 KB
Original Source

--description--

You don't need the count variable anymore. Delete this variable and its value.

--hints--

You should delete the count = 0 line.

js
({ test: () => {
    const commentless_code = __helpers.python.removeComments(code);
    assert.isFalse( /count\s*=\s*0/.test(commentless_code))
  }
})

--seed--

--seed-contents--

py
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}]')            
        ]
--fcc-editable-region--
        # Check constraints
        count = 0
        if all(
            constraint <= len(re.findall(pattern, password))
            for constraint, pattern in constraints
        ):
--fcc-editable-region--
            break
    
    return password

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