Back to Freecodecamp

Step 18

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

latest1.1 KB
Original Source

--description--

A standalone single underscore is used to represent a value you don't care or that won't be used in your code. Your iteration variable is not actually used.

Modify your i variable into a single underscore.

--hints--

You should modify your i variable into _.

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(/for\s+_\s+in\s+range\s*\(\s*length\s*\)\s*:/));
  }
})

--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 i in range(length):
        password += secrets.choice(all_characters)
    
--fcc-editable-region--