If you’re getting the “Failed to test your code” error, try refreshing the page. It fixed the problem for me after going through several frustrating lessons just dealing with it.

without seeing your code and other relevant information, its really difficult to tell what the problem might be. The most obvious cases being no print statement/function call or the print statement isn’t executed/reached for some reason.

The function our main call will go to (by_three()) will conditionally call the helper function (cube()).

First the maths…

a => symbol for any number
a ** 2 => exponential expression => a_squared
a ** 3 => a_cubed

We know that the square of a number is that number times itself…

a ** 2 => a * a

and the cube of a number is that number times itself, and times itself again.

a ** 3 => a * a * a

Generally, a raised to any exponent n is,

a ** n => a * a * ... * a (n times)

Module division yields a remainder from normal division instead of a quotient.

17 / 3 => 5, with 2 remainder

so,

17 % 3 => 2

Our helper function is very straight forward and it returns what the name says… cube of number

def cube(number):
return number ** 3

The main function takes a number and examines if it is divisible by 3 (n % 3 == 0) whereupon it returns the cube of that number.

if number % 3:
return cube(number) # call to the helper function

The return value from the main function will be the number returned from the helper function.

This line will return None to our caller (the call to the main function) since print() has no return. A better approach might be to simply return the message string, and print at the caller.

print (by_three(18)) # 5832
print (by_three(17)) # enter different number

In the expression we use == which is not an assignment. We are not setting, only comparing it to zero. The modulo operator is also called the remainder operator since it returns the remainder from division, not the quotient. Any number that is divisible by 3 will result in a zero remainder.

if n % 3 == 0 => then `n` is evenly divisible by 3.

Hi i used the print at the end of the code, but the values were not displayed.
Here is my code, can someone please explain me why this is not happening?