Need guidance on my program error

I started learning Python only last week,I am trying to write a password set-up and validation program for practice. The below is the code

set_password = input('set-up your password: ')
set_password_length = len(set_password)

if set_password_length >= 8:
    elif set_password_length < 20:
        re_confirm_password = input('reenter your password: ')
        print('password cannot be longer than 20 characters')
    print('password should be minimum 8 characters long')

if set_password == re_confirm_password:
    print('you have successfully set your password')
    login_password = set_password
    print('please enter the same password')

number_of_attempt = 1
while number_of_attempt <= 3:
    number_of_attempt = number_of_attempt + 1
    enter_password = input('Enter your password: ')
    if enter_password == login_password:
        print('login successful')
    print('you exceeded the limit,your account is locked')

but python is complaining about the break statements .Can anybody help to understand the mistake and guide me.

Thank you.

break keyword can be used only within while or for loop, as an way to end that loop earlier than waiting for for loop to iterate over all elements or while loop’s condition start to be False. Usually it’s used when certain additional condition, making further looping obsolete, is met.


I’ve edited your post 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 (’).

Thank you so much for your guidance.

Sorry this was my very first post…i’ll definitely adhere to the practice in future.
Thank you so much for support.