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
# User Editable Region
password = ''
# Generate password
for i range(length) :
password += secrets.secrets(all_characters)
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Learn Regular Expressions by Building a Password Generator - Step 17
You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!
Hi @hai1009 and welcome to fCC community.
The task requested that 1st to create a for loop.
Below eample of a for loop using x as variable, and used range to iterate over the values in value
If you don’t have anything to code into the loop yet, you can use pass to hold the space and avoid error.
for x in range(value):
pass
For the 2nd part that should replace pass above, let’s say I want to "use the multiplication assignment operator to add a random character from var_two to the current value of value_1. Use the randint() function from the random module.
The code will now go like:
for x in range(value):
value_1 *= random.randint(var_two)
Hope this gets you unstuck.
Let me know if it works.