Learn Regular Expressions by Building a Password Generator - Step 61

Tell us what’s happening:

all() is a built-in Python function that returns True if all the elements inside a given iterable evaluate to True. Otherwise, it returns False.

Replace your existing for loop and two if statements with a single if statement. For the if condition, use a call to the all() function and pass an empty list as the argument to the function. What do I do?

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

        # Check constraints
        count = 0

# User Editable Region

        if pattern in constraints all( count = []):
            break
           
            
       

# User Editable Region

            break

    return password

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 61

Just send the code…nothing is working

try to remove this.
The condition of the if should be only all([]).

It still doesn’t work

post your code please

if all( count = ):
break

This doesn’t work too

why there is count inside all? the argument is only an empty list

if all():
break
This doesn’t run too

post the whole code and please format it properly, that looks good

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 (').

all() is a built-in Python function that returns True if all the elements inside a given iterable evaluate to True. Otherwise, it returns False.

Replace your existing for loop and two if statements with a single if statement. For the if condition, use a call to the all() function and pass an empty list as the argument to the function. What do I do?

if all():
break

I mean this how my code look like after I formatted

I don’t see any formatting, please use the correct markdown, and copy and paste all the code from the editor, not only from the editable region

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

        if  all( [ ]):
            break
           
            
       

# User Editable Region

            break

    return password

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

there

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 (').

I would make the spacing more consistent in this if line

You also have break twice

Please format your code using the code button indicated in my previous comment. Without that we cannot see the indentations and formatting which is crucial to understand Python code.

Screenshot 2024-05-01 120157

Here is some good guidance on spacing:
https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements