Back to Freecodecamp

Step 25

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

latest1.2 KB
Original Source

--description--

After your for loop, create a constraints variable and assign an empty list to this variable.

--hints--

You should declare a constraints variable after your for loop and assign an empty list to this variable.

js
({ test: () =>
  {
    const transformedCode = code.replace(/\r/g, "");
    const generate_pw = __helpers.python.getDef("\n"+transformedCode, "generate_password");
    const {function_body} = generate_pw;     
    assert(function_body.match(/^(\s*)for.*:.*^\1constraints\s*=\s*\[\s*\]/ms));
  }
})

--seed--

--seed-contents--

py
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
--fcc-editable-region--
    while True:
        password = ''
        # Generate password
        for _ in range(length):
            password += secrets.choice(all_characters)
        
--fcc-editable-region--
    return password

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