Nicholas Harker
Nicholas Harker

Reputation: 3

Method not returning as True

I am trying to return True from the isCorrect method to the correctMessage method. But correctMessage does not run right due to isCorrect outputting "function isCorrect at 0x000000"

def correctMessage(isCorrect, tryAnswer, questionAnswer):
    if isCorrect is True:
        return print("Yes! You answered \"", 
                     str(tryAnswer), "\" and the answer was " + questionAnswer)

def isCorrect(tryAnswer, questionAnswer):
    if str(tryAnswer).lower() == questionAnswer:
        return True
    return False

What can I do for this to be evaluated correctly?

Upvotes: 0

Views: 58

Answers (3)

Thmei Esi
Thmei Esi

Reputation: 442

def correctMessage(isCorrect, tryAnswer, questionAnswer):
    if isCorrect(tryAnswer, quenstionAnswer):
        print("Yes! You answered \"", str(tryAnswer), "\" and the answer was " + questionAnswer)

def isCorrect(tryAnswer, questionAnswer):
    return str(tryAnswer).lower() == questionAnswer:

Upvotes: -1

Shadow
Shadow

Reputation: 9437

You need to call isCorrect with the parameters you wish to pass to it. You're currently checking to see if the physical function isCorrect is equal to True - which it isn't.

Upvotes: 1

ShadowRanger
ShadowRanger

Reputation: 155704

You didn't call isCorrect, you tested if the function itself was True. Add parens and pass the two arguments isCorrect requires.

Side-notes: You didn't need if with two returns in isCorrect. return str(tryAnswer).lower() == questionAnswer would do the exact same thing faster.

Similarly, testing if x is True: is ugly, and almost always wrong, just test if x: unless the value True is really important and different from all other truthy values (in this case, it's the only truthy possibility, so it's faster and more Pythonic to just do if isCorrect(...):).

Upvotes: 1

Related Questions