You do not catch the return value of the cube function. Make 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
When you call the cube function with argument b , it returns the cube of the passed argument, you need to save it in a variable and return it to the user, in your current code, you neglect the return value.
source share