Practice makes perfect Problem


it seems everything ok. But i'm facing "Oops, try again. by_three(6) returned 27 instead of 216" . Any idea what is happening here.?



return cube(3)

you always return cube of 3, regardless of what number is, return cube of number


I'd written it a little differently and it passed me, however I'm a little confused about the "if n % 3 == 0" portion, I don't understand why, in le mans terms, if the number (let's call it 2) can't have 3 put into it once, meaning the equation is equal to 0, why it would point you back up to def cube(n) and if it doesn't why it would fail. I'd think it should be "if n % 3 >= 1" return cube(n), since only a number that is 3 or greater can be divided by 3. Does that make since or do I need to work on my wording? haha, just wanting to understand this to the maximus!

def cube(n):
    return n**3

def by_three(n):
    if n % 3 == 0:
      return cube(n)
        return False


no? we two isn't divisible by 3, so after attempting dividing 2 by 3, which didn't work, we are left with 2, two doesn't equal zero


Right but 2 divided by 3 is 0.66... not zero, so it gets sent to the return false section. but let's say the number is 30, 30 divided by 3 is 10, again, not zero, so it also should return false right?


yes, but % calculates the remainder. lets do another example:

11 % 3

the biggest possible division is 9 (9 / 3), 12 is no longer possible (12 / 3) because 12 is higher then 11.

so then the remainder is 2 (11 -9), given we have two left after the biggest possible division of 11 divided by 3

in your example, 2 is lesser then 3, then 2 is the remainder (given zero is the biggest possible division)


Oh I see, gotcha. Thanks for the reference with example @stetim94 I've been able to understand most of what the academy teaches thusfar but unfortunately math operations usually grind my gears a little slower lol


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.