Ad

Python Keeps Showing Access Denied! Why Isn't It Recognising Value?

- 1 answer

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 :)

Ad

Answer

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".

Ad
source: stackoverflow.com
Ad