Back to Freecodecamp

Step 20

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

latest1.1 KB
Original Source

--description--

Finally, declare a variable new_password and assign it the result of calling generate_password. Pass 8 as the argument to your generate_password call.

--hints--

You should call generate_password passing 8 as the argument.

js
({ test: () => assert.match(code, /generate_password\s*\(\s*8\s*\)/) })

You should assign generate_password(8) to the variable new_password.

js
({
  test: () => {
    assert(__userGlobals.has("new_password"));
    assert.match(code, /^new_password\s*=\s*generate_password\s*\(\s*8\s*\)/m);
  }
})

--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

    password = ''
    # Generate password
    for _ in range(length):
        password += secrets.choice(all_characters)
        
    return password
    
--fcc-editable-region--

--fcc-editable-region--