Learn Regular Expressions by Building a Password Generator - Step 24

Tell us what’s happening:

Hello everyone. I am on step 24 of Learn Regular Expressions by Building a Password Generator. I believe that I have completed the assignment as instructed, but my code does not pass. I assume the error is in my indentation of the while loop, but I cannot seem to find an indentation that satisfies the requirements.

The specific line is

while True:
  password = ''
  # Generate password
  for _ in range(length):
     password += secrets.choice(all_characters)

Cheers

Your code so far

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

# User Editable Region

    while True:
      password = ''
      # Generate password
      for _ in range(length):
         password += secrets.choice(all_characters)

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

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 24

Yeah, write it again using two tabs instead of spaces. The same code passes when two tabs are used.

Can you please clarify which line you mean? I did not actually hit space when indenting (to my knowledge)

Start with doing as it says, write the While True: above the password =. Then indent everything up to password += using two tabs.
Oh, click reset before you do it to get you in a clean state. It will not delete progress.

1 Like

Thank you for your help!

1 Like

Helloo, I had the same error as @spencergauert , but why does the while loop require two indentations? I can´t understand :smiling_face_with_tear:

Every time you create a new Class, function or loop you need to indent the code to indicate it’s part of that block

while loop:
    code
    code
    if statement:
        code
        code

If you have any more questions, please open a new thread, thanks!

1 Like