Python Function that returns None

Mabe

I don't understand, why is foo() returning None?

def foo(a,b):
    if a+b == 12:
        return True
print(foo(7,5)) # Works fine
print(foo(1,3)) # prints None
Some Guy

You should return another bool if a+b is not 12

def foo(a,b):
    if a+b == 12:
        return True
    else:
        return False
answer1 = foo(1,3)
answer2 = foo(7,5)
if answer1:
    print "1 + 3 = 12"
if answer2:
    print "7 + 5 = 12"

foo() will return True if a+b == 12, if not should return False

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related