freeCodeCamp.org

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

I belive my while True loop is correct.I am not able to complete this step due to level of indentation. I am doing what this post say
Also, my editor doesn’t report any error …the script run pefectly.
I am wondering if you can give me a trick to easily find out the issue with the level of indentation.

Thanks

here you have different levels of indentation, they need to match, they should be 8 spaces from the beginning of the line

Dear Ilenia…I am trying and trying but nothing. What is strange that on my editor code run without any issue. And my editor does the indentation automatically . What I am doing wrong??
the script below run without problem in my editor.

import secrets
import string

def generate_password(length):
    # 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)
        return password
    
# new_password = generate_password(8)
# print(new_password)

the things inside the while loop need to be indented 8 spaces, the things inside the for loop by 12

I do not know…I tried all the cobination…I give up for today…

this line is indented by 5 spaces, the following one by 4, you need to put this in line with the others

Also return password should not be in the for loop. I don’t understand having the while loop. It is not being used.

the while is going to execute, creating a different password at each iteration, until the password satisfy all given costraints

sorry I must be tired now: it doesn’t work for me. …I will try later…thank you all…

I understand, now that I’ve seen the exercise.

You’re auto-formatter does not seem reliable. Especially since it can only interpret your intention.

I don’t think you should use an auto-formatter when you are learning Python. The formatting is syntax, and not just for readability.

Guys…I do not know… This is not normal, I can not move to the next step. I did all the indentation combinations but nothing. I made the code in my Visual studio code and run it immediately and worked fine. It from last night that I am not able to move on.

Put your password variable declaration and the following for loop inside a while loop.

The fCC editor has lines where you can clearly see the different indentations

Screenshot 2024-03-20 141027

Everything in the same block of code should be at the same indentation.

You only need to do the correct one. Show your updated code here.

This is normal actually.

while loop:
    code
    code
    for loop:
        code
        code

This is an example of indentation of a for loop nested in a while loop.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.