Learn Regular Expressions by Building a Password Generator - Step 71

Tell us what’s happening:

This one is for sure i need help so please look into the code and let me know why its not passing so that i can correct it rigth away.

Your code so far

import re
import secrets
import string


def generate_password(length=16, nums=1, special_chars=1, uppercase=1, lowercase=1):

    # 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)
        
        constraints = [
            (nums, r'\d'),
            (special_chars, fr'[{symbols}]'),
            (uppercase, r'[A-Z]'),
            (lowercase, r'[a-z]')
        ]

        # Check constraints        
        if all(
            constraint <= len(re.findall(pattern, password))
            for constraint, pattern in constraints
        ):
            break
    
    return password
    

# User Editable Region

new_password = generate_password()
print('Generated password:' + 
new_password)

# 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/136.0.0.0 Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 71

you did not add a new argument to print, you are concatenating to the existing string

the requirement is a new argument

Hi there,

Your print statement has a small issue:

  • The new_password should be on the same line, not the next.
  • Also, try not to use + for combining values in print — there’s a safer way that avoids potential issues.

Keep it up — you’re very close!

ok let me give it a shot.

How can i combine both if i am not using + sign can you please tell me?

how do you separate arguments usually when you call a function with multiple arguments?

for example, when you were calling generate_password with multiple arguments

i guess by using comma in the sentence let me give it a try and will let you know if that works.