LtC LtC - 4 months ago 18
Python Question

(Beginner)Python functions Codeacademy

im just learning to program here , so bear with me here.
Im learning to code on Codeacademy and have an assignment, but cant figure out for the life of me what im doing wrong.

First i need to define a function that returns the cube of a value, than i should define a second function that checks if a number is diviseble by 3, if it is i need to return it , else i need to return a 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

Answer

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.

Comments