Learn Regular Expressions by Building a Password Generator - Step 26

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

import secrets
import string

def generate_password(length, nums, special_chars, uppercase, lowercase):
    # 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

    while True:
        password = ''
        # Generate password
        for _ in range(length):
            password += secrets.choice(all_characters)

/* User Editable Region */

        constraints = []
        constraints.append((nums, ''))

/* User Editable Region */

    return password

# new_password = generate_password(8)
# print(new_password)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 26

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.

Hi, welcome to the forum!
We see you have posted some code but did you have a question?

(You have not filled out the “Tell us what’s happening:” field above)

Don’t use append, just modify the existing list assignment

1 Like

Hi thanks for your response, I have replaced

constraints = []
constraints.append((nums, ''))
constraints = []
constraints[0] = (nums, '')
constraints = list()
constraints[0] = (nums, '')

but neither of them works.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Edit the existing line where you declare the list.

Don’t add a new line

1 Like

I see! Now I get your point.

Alright! Thanks for pointing it out to me!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.