# Learn Regular Expressions by Building a Password Generator - Step 62

**URL:** <https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [December 30, 2023, 1:32pm UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730 "2023-12-30T13:32:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brice](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@Brice](https://forum.freecodecamp.org/u/Brice)\
**Post date:** [December 30, 2023, 1:32pm UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/1 "2023-12-30T13:32:15Z")

</div>

### Tell us what’s happening:

Describe your issue in detail here.

Hi team. I need help to solve this step. Here is my code so far.  
`Preformatted text`

### Your code so far

```py
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}]')            
        ]

        # Check constraints
        count = 0

/* User Editable Region */

        all([constraint <= len(re.findall(pattern, password))
        for constraint, pattern in constraints]):

/* User Editable Region */

            break
    
    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 Edg/120.0.0.0`

### Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 62

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-regular-expressions-by-building-a-password-generator/step-62)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [December 30, 2023, 1:32pm UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/2 "2023-12-30T13:32:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HungryBee](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hungrybee/32/345970_2.png) [@HungryBee](https://forum.freecodecamp.org/u/HungryBee)\
**Post date:** [December 30, 2023, 1:46pm UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/3 "2023-12-30T13:46:34Z")

</div>

Hello Brice,

Very close! But right the question at the beginning said:

> Modify your if condition

I don’t see an if statement anymore. (As a hint, you are to check `if` all elements are True).

---

<div class="post-metadata">

**Author:** ![eric88vo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eric88vo/32/348555_2.png) [@eric88vo](https://forum.freecodecamp.org/u/eric88vo)\
**Post date:** [January 16, 2024, 9:53am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/4 "2024-01-16T09:53:15Z")

</div>

@HungryBee  
I think I follow what it is that you are saying.  
Take the If and place it around the all() function and within the all() is contains all the conditions.  
I am still stuck and can’t get it to run.  
see code below:

* * *

```auto
if all (constraint <= len(re.findall(pattern, password))
            for constraint, pattern in constraints):

```

* * *

Is there a glaring mistake I am making here.  
THank you in advance.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2024, 9:54am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/5 "2024-01-16T09:54:53Z")

</div>

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.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2024, 9:55am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/6 "2024-01-16T09:55:14Z")

</div>

The if statement condition has to have a specific character to conclude it, do you remember what it is?

---

<div class="post-metadata">

**Author:** ![eric88vo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eric88vo/32/348555_2.png) [@eric88vo](https://forum.freecodecamp.org/u/eric88vo)\
**Post date:** [January 16, 2024, 9:57am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/7 "2024-01-16T09:57:32Z")

</div>

> [@ILM](#):
>
> has to have a specific character to conclude it, do you remember what it is?

Thank you for the formatting correction.

All I can think of a colon for the end of an if statement. 🤔

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2024, 9:58am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/8 "2024-01-16T09:58:55Z")

</div>

that can be the answer, yes, do you have it in your code?

---

<div class="post-metadata">

**Author:** ![eric88vo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eric88vo/32/348555_2.png) [@eric88vo](https://forum.freecodecamp.org/u/eric88vo)\
**Post date:** [January 16, 2024, 10:07am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/9 "2024-01-16T10:07:28Z")

</div>

This is the updated code I have tried. It is still not working. I am certain the mistake is something small and silly.

```auto
if [all (constraint <= len(re.findall(pattern, password))
            for constraint, pattern in constraints)]:
                break

```

P.S. is this the correct formatting?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2024, 10:09am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/10 "2024-01-16T10:09:49Z")

</div>

I don’t see you adding a colon at the end of the if statement condition

what are those square brackets you added?

---

<div class="post-metadata">

**Author:** ![eric88vo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eric88vo/32/348555_2.png) [@eric88vo](https://forum.freecodecamp.org/u/eric88vo)\
**Post date:** [January 16, 2024, 10:20am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/11 "2024-01-16T10:20:06Z")

</div>

Those square brackets were just an attempt to try somthing different.

These are the versions of the code I have tried so far focussing on trying to complete the if statement.

```auto
if (all (constraint <= len(re.findall(pattern, password))
            for constraint, pattern in constraints):):
            break

```

```auto
if all (constraint <= len(re.findall(pattern, password))
            for constraint, pattern in constraints)::
            break

```

I can see I need a colon at the end of the statement for 'if ’ and the ‘all()’ statements and functions, respectively. Am I missing something really silly here?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2024, 10:22am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/12 "2024-01-16T10:22:00Z")

</div>

> [@eric88vo](#):
>
> `if all (constraint <= len(re.findall(pattern, password))`

this is your if statement condition, it needs a colon at the end  
`all()` doesn’t need a colon at the end  
the for loop is indise the if statement but is not part of the if statement condition

---

<div class="post-metadata">

**Author:** ![eric88vo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eric88vo/32/348555_2.png) [@eric88vo](https://forum.freecodecamp.org/u/eric88vo)\
**Post date:** [January 16, 2024, 10:35am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/13 "2024-01-16T10:35:59Z")

</div>

> [@eric88vo](#):
>
> if all (constraint \<= len(re.findall(pattern, password))

Ok perfect, thank you that makes sense to me now.

However, the code is still not working.  
I have tried resetting the code block and puting the code in again.

```auto
if all (constraint <= len(re.findall(pattern, password))):
            for constraint, pattern in constraints:
                break

```

That is my updated code. My question now is. Is the ‘break’ still required? Would it not be implemented on the first iteration through the for loop?

---

<div class="post-metadata">

**Author:** ![eric88vo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eric88vo/32/348555_2.png) [@eric88vo](https://forum.freecodecamp.org/u/eric88vo)\
**Post date:** [January 16, 2024, 11:08am UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/14 "2024-01-16T11:08:24Z")

</div>

I solved it by jumping ahead to the next stage and looking at the code there.  
Here are some pointer for you if you do want to stick to the learning and solving fun.

Place the all() function within the if statement:  
I see it as a **if all ( …conditions etc… ):**  
Keep the []'s around the whole argument both the test for \<= and for loop.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![pkdvalis](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pkdvalis/32/350571_2.png) [@pkdvalis](https://forum.freecodecamp.org/u/pkdvalis)\
**Post date:** [January 16, 2024, 8:32pm UTC](https://forum.freecodecamp.org/t/learn-regular-expressions-by-building-a-password-generator-step-62/659730/15 "2024-01-16T20:32:08Z")

</div>


