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

Python keeps showing Access denied! Why isn't it recognising value?

Python keeps sendin me to wrong password, idk why, anyone have any idea, btw its my first time in python 🙂

i=3
    def pw():
        global i
        if i==3:
                p=1312
                print('Input the password:')
                print('[You have 3 tries to guess the password!]')
                pu = input()
                if pu == p:
                    print('Access Granted!')
                elif pu != p:
                    print('Access Denided!')
                    print('Passwords dont match!')
                    i-=1
                    pw()
        elif i==2:
                p=1312
                print('------------------------------------------------------------------------------------------------------------------------')
                print('Input the password:')
                print('[You have 2 tries to guess the password!]')
                pu = input()
                if pu == p:
                    print('Access Granted!')
                elif pu != p:
                    print('Access Denided!')
                    print('Passwords dont match!')
                    i-=1
                    pw()
        elif i==1:
                p=1312
                print('------------------------------------------------------------------------------------------------------------------------')
                print('Input the password:')
                print('[You have 1 try to guess the password!]')
                print('NOTE: If you dont guess the password the computer will shutdown!')
                pu = input()
                if pu == p:
                    print('Access Granted')
                elif pu != p:
                    print('Access Denided!')
                    print('Passwords dont match!')
                    print('------------------------------------------------------------------------------------------------------------------------')
                    
                    i-=1
                    pw()
    
    
    print('Welcome to Your first project.')
    print('Please input wanted paramaters!')
    print('Please input your name and surname:')
    Name = input()
    print('Nice to meet you '+ Name)
    pw()

Python keeps sendin me to wrong password, idk why, anyone have any idea, btw its my first time in python 🙂

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 :

p is of type number, while pu is of type string. You compare a string with a number, so you get False. Try replacing p=1312 with p="1312".

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