I'm trying to learn Python and I tried making just a little "Secret" protected by a password. I also tried to make it so if you typed "help" it would give you a hint. Well I made it so when you type anything that's not the password it would say incorrect and you'd try again. It almost works perfectly except when I type "help" or input the correct password, the "incorrect" still comes up and I have to retype the correct password, which then works. What did I do wrong?

def helpInfo():
    print('The Password is a single Number')

def secret():
    print ('Secret password protected stuff blah blah blah')

def intro():
    print('Hello! What is the Password?')

def check():

    password = 3
    guess = input()

    if guess == password:
        print ('Correct!')

    if guess == help:
        helpInfo()

    if guess != password or help:
        print ('Incorrect! Please try again')
        check()


intro()
check()

wrong type, watch this magic:

>>> a=input('code: ')
code: 3
>>> a==3
False
>>> a
'3'
>>> print(3)
3
>>> type(a)
<class 'str'>
>>> type(3)
<class 'int'>
>>> a=int(a)
>>> a==3
True

input creates a string, if you want it to be an integer you need to be explicit about it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.