-2

If the password input is right it will print('OKAY') , and if the input is wrong it will say print('wrong password')

name=input("Enter your name: ")
print("Hello, " + name)


LEGAL_AGE=18
 age = int(input("Please enter your age: "))

 if age<18 :
    print("GO HOME")
 else:

    password =input("TYPE YOUR PASSWORD : ")


    if password==int(12345):
       print('YES , YOU CAN ENTER NOW')
 else:
    print('WRONG')

1 Answers1

0

You need to do it like this for it to work -

name=input("Enter your name: ")
print("Hello, " + name)


LEGAL_AGE=18
age = int(input("Please enter your age: "))

if age<18 :
    print("GO HOME")
    
else:
    password =input("TYPE YOUR PASSWORD : ")
    
    if int(password)==12345:
       print('YES , YOU CAN ENTER NOW')
    else:
        print('WRONG')

In your code, you are converting an already integer to int in the statement int(12345) which essentially doesn't have any effect. You need to convert the password to integer which is read by python as a string.

Do note that you are not required to convert the password to an integer, you can check it against a string as well like -

name=input("Enter your name: ")
print("Hello, " + name)


LEGAL_AGE=18
age = int(input("Please enter your age: "))

if age<18 :
    print("GO HOME")
    
else:
    password =input("TYPE YOUR PASSWORD : ")
    
    if password=='12345':
       print('YES , YOU CAN ENTER NOW')
    else:
        print('WRONG')

Both the above methods are correct.

Abhishek Bhagate
  • 5,583
  • 3
  • 15
  • 32