Back to Freecodecamp

Step 21

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

latest772 B
Original Source

--description--

Check the result by printing your new variable.

--hints--

You should print new_password.

js
({ test: () => assert.match(code, /^print\s*\(\s*new_password\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--
new_password = generate_password(8)

--fcc-editable-region--