Back to Freecodecamp

Step 19

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

latest1.0 KB
Original Source

--description--

After the loop, add a return statement to your function so it returns the password variable.

--hints--

You should return password at the end of your function.

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\s+\w\s+in\s+range\s*\(\s*length\s*\)\s*:.+^\1return\s+password/ms));
  }
})

--seed--

--seed-contents--

py
import secrets
import string


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