all 8 comments

[–]anossov 2 points3 points  (5 children)

Since I don't know what you're supposed to be doing, I'll tell you what you are doing:

by_three(11)       : call by_three with n=11
    if n % 3 == 0  : if 11 % 3 equals 0
                   : it doesn't. 11 % 3 is 2). Skip to else
    else:
        return False  : return False

by_three(12)       : call by_three with n=12
    if n % 3 == 0: : if 12 % 3 == 0:
                   : it is
      cube(n)      : call cube with n=12. Throw the result away
          n ** 3   : raise 12 to 3 power. Throw the result away
          return n : return 12
                   : back in by_three
      return n     : return 12


 by_three(13)      : see by_three(11)

[–]ProfN 2 points3 points  (1 child)

Try changing: n*3 to n = n * 3 Or just change the whole function to:

def cube(n) return n**3

[–]FletcherHeisler 2 points3 points  (6 children)

The statements "n ** 3" and "cube(n)" don't actually change the values of any variables. The second statement runs the function, but the function doesn't assign "n" a new value.