Scientific Computing with Python question mistake? Password generator

In question 61 of the Scientific Computing with Python certification, Password Generator, I am entering in

if all([]):
            break

But this is not working. I am unsure as to why this is the case and think there might be a mistake with the question itself.

Your indentation isn’t correct in the code you posted.

    if all([]):
        break

This is returning " Sorry, your code does not pass. Keep trying. You should have break inside your new if body." The indentation there is okay, but it’s saying that there should be a break inside the section with the if loop (which there is).

What is your full code?

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
        if all([]):
            break
            break

    return password

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

Oh, there were two break statements! It’s working now!

1 Like