Learn Regular Expressions by Building a Password Generator - Step 59

Tell us what’s happening:

hey everyone, ive been trying to solve this piece but nothing seems to work so far, because they would tell me “Your code raised an error before any tests could run. Please fix it and try again.” and im not sure what im doing wrong.

Your code so far

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

# User Editable Region

        # Check constraints
        count = 0
        for constraint, pattern in constraints:
            constraint <= len(re.findall(pattern, password))

# User Editable Region

    return password

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 59

Hello Lee,

Does it give you that error even after you reset the step and run it without touching anything?

Yep :frowning_face:
I’m not sure whyyy

Alright well can you try following the question and show us what you tried?

Im on my phone rn so its not easy for me to show it, but from my previous attempts, just by adding “if” in fromt of the condition automatically gives that output.

Did you also do this part increment the count value by 1 and make sure it’s a proper if statement by using the right syntax?

If so you can post your code once you are able to.

2 Likes

hey @HungryBee , I’ve managed to solve it, i just had to add the increment part as u said, and placed the if in front, it worked! thank you for your guidance.

2 Likes

im also stuck on this one… how can I increment the value by 1? hint please

solved it! hehe <3 have a good one

Please open a new topic for your questions, thanks!