curriculum/challenges/english/blocks/learn-regular-expressions-by-building-a-password-generator/65648f4b2281ba50051ae39c.md
Next, write a for loop with i as the loop variable. Use the range() function to iterate up to the value of the length.
Inside the loop, use the addition assignment operator to add a random character from all_characters to the current value of password. Use the choice() function from the secrets module for that.
You should write a for loop that iterates over range(length).
({ 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+i\s+in\s+range\s*\(\s*length\s*\)\s*:/));
}
})
You should use the += operator to add a random character from all_characters to the current value of password.
({ test: () =>
{
const generate_pwd = __helpers.python.getDef(code, "generate_password");
const {function_body} = generate_pwd;
assert(function_body.match(/^(\s*)for\s+i\s+in\s+range\s*\(\s*length\s*\)\s*:\s*^\1\1password\s*\+=\s*secrets\.choice\s*\(\s*all_characters\s*\)/m));
}
})
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
--fcc-editable-region--