user392500 user392500 - 1 month ago 10
Python Question

Python functions returning none for some reason

I'm having some issues with these python functions. Whenever I run them, it saying function by_three is returning none. Any help would be appreciated.

def cube(number):
result = number**3
return result

def by_three(number):
if number%3 == 0:
cube(number)
else:
return False

Answer Source

In the if case your function ends without returning anything. This is why you get None back. You probably meant:

def cube(number): 
    result = number**3 
    return result
def by_three(number): 
    if number%3 == 0:
        return cube(number)
    else:
        return False