Reputation: 35
I have a Python code like this,
def cube(n):
n = n * n * n
return n
def by_three(n):
if (n % 3 == 0):
print "number is divisible by three"
cube(n)
return n
else:
print "number is not divisible by three"
return False
Currently I am not able to return any value, please let me know what is the issue?
Upvotes: 0
Views: 110
Reputation: 53718
You do not set the value of cube(n)
in your by_three
function to return.
def cube(n):
result = n ** 3 # You can use ** for powers.
return result
def by_three(n):
if (n % 3 == 0):
print "number is divisible by three"
result = cube(n)
return result
else:
print "number is not divisible by three"
return False
I am also assuming that you have made a mistake in your indentation when copying to SO. If that is not the case, and that is your original indentation, then you will need to rectify that also.
Upvotes: 6