I'm just learning to program on Codeacademy. I have an assignment, but cant figure out what I'm doing wrong.
First I need to define a function that returns the cube of a value. Then I should define a second function that checks if a number is divisible by 3. If it is I need to return it, otherwise I need to return False
.
heres the code:
def cube(c):
return c**3
def by_three(b):
if b % 3 == 0:
cube(b)
return b
else:
return False
You are not catching the return value of the function cube
. Do b = cube(b)
. Or better yet, do return cube(b)
.
def cube(c):
return c**3
def by_three(b):
if b % 3 == 0:
b = cube(b)
return b # Or simply return cube(b) and remove `b = cube(b)`
else:
return False
When you call the cube
function with the argument b
, it returns the cube of the passed argument, you need to store it in a variable and return that to the user, in your current code, you are neglecting the returned value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With