The step is " 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."
I’ve tried many things but don’t know exactly what the mistake is. Please help
Your code so far
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
/* User Editable Region */
# Combine all characters
all_characters = letters + digits + symbols
password = ''
# Generate password
for i in range(length):
secrets.choice(all_characters += password)
/* User Editable Region */
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Challenge Information:
Learn Regular Expressions by Building a Password Generator - Step 17
Ok, so then on the left side of += needs to be the password variable an on the right you need to put the thing you want to add to the password, which is the result from secrets.choice().
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.