6/19 Practice Makes Perfect (Functions)


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

Above is the code I have in the editor. It works for the exercise (I can move on to the next exercise fine). However, when I test the code, it will print the number cubed regardless to if it is divisible by three or not. Why?


#2

running this code should produce no output, there are no function calls to execute the functions.

yes, by_three calls cube, but you never call cube or by_three from outside any function


#3

Thanks. I did call a function when I was testing it, but I called cube(num) rather than by_three(num).


#4

well, the purpose of cube function is to return the cube (there is a surprise :stuck_out_tongue: ) , regardless wether or not divisible by three

But then you also answered your own question?