Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Login system with number of tries on python how can i simplify it?

I am a Beginner in Python and i made this login system with number of tries. I think it can be simplified Can anyone help?

a=int(input("Enter the Password: "))
i=5
if a==1234:
        print("ACCESS GRANTED")
        
while not a==1234:
    print(f"INVALID PASSWORD ( {i} times left)")
    a=int(input("Enter the Password: "))
    i-=1
    if a==1234:
        print("ACCESS GRANTED")
    if i==0:
        print("Console has been locked")
        break

I tried it to change the number of print("ACCESS GRANTED") but I dont get how to without doing it wrong.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Maybe something like this:

a = 0
i = 6
while not a==1234:
    a=int(input("Enter the Password: "))
    i-=1
    if a==1234:
        print("ACCESS GRANTED")
    elif i==0:
        print("Console has been locked")
        break
    else:
        print(f"INVALID PASSWORD ( {i} times left)")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading