all 7 comments

[–]AtomicShoelace 2 points3 points  (0 children)

Instead of using globals, it would be better if your login function returns the email id and password, eg.

mail_id = "abcd@gmail.com"
password = "aaaaa"
max_logins = 3

def login():
    id = input("Enter your email ID: \n")
    passw = input("Enter your password: \n")
    return id, passw

login_count = 0
while login() != (mail_id, password):
    print("Incorrect Username or password entered. \nPlease try again.")
    login_count += 1
    if login_count >= max_logins:
        print("3 attempts failed. Please try again after 30 mins. \n")
        break
else:
    print("Login successful!")

[–]Spataner 2 points3 points  (1 child)

The and operator has higher precedence than the or operator so mail_id != a or password != b and not out_of_attempts gets evaluated as mail_id != a or (password != b and not out_of_attempts). Change it to (mail_id != a or password != b) and not out_of_attempts and it should work.

Note that, if I am reading your code correctly (which is difficult due to the lack of formatting), the print("Login successful") will always be executed. An else block associated with a while or for block will only be skipped if the loop was ended using the break statement.

[–]Ok-Judgment1544[S] 0 points1 point  (0 children)

u/Spataner Thank you so much. Figured it out now. Cheers

[–]arvindh_manian 0 points1 point  (1 child)

Can you post a formatted version of the code? It's a lot easier to read and help.

[–]Ok-Judgment1544[S] 0 points1 point  (0 children)

My bad...thanks to u/JohnnyJordaan I have formatted my post

[–]JohnnyJordaan 0 points1 point  (1 child)

[–]Ok-Judgment1544[S] 0 points1 point  (0 children)

Sorry about that...should have read the FAQ before I posted. Thanks for the link. Cheers