This community-built FAQ covers the “Practice Makes Perfect” exercise in Codecademy’s lessons on Python.
FAQs for the Codecademy Python exercise Practice Makes Perfect:
Join the Discussion. We Want to Hear From You!
Have a new question or can answer someone else’s? Reply () to an existing thread!
Agree with a comment or answer? Like () to up-vote the contribution!
Need broader help or resources about Python in general? Go here!
Want to take the conversation in a totally different direction? Join our wider discussions.
Learn more about how to use this guide.
Found a bug? Report it!
Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!
None of the above? Find out where to ask other questions here!
A post was split to a new topic: Modulo operator
12 posts were split to a new topic: [No Response] What is the solution?
5 posts were split to a new topic: Practice makes perfect
2 posts were split to a new topic: Practice makes perfect - cube
Another broken lesson, sigh
Broken how? Can i see your code and error message? Then i can make a bug report.
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.
why its not printing the result?
Please see this topic:
How to ask good questions (and get good answers)
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.
Hi, i’m a beginner and i’m lost on this lesson. Any help/advice?
this is what i wrote:
if number % 3 == 0:
return print “enter different number”
There is some math in the lesson:
The logic includes,
The function our main call will go to (
by_three()) will conditionally call the helper function (
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
a raised to any exponent
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
17 % 3 => 2
Our helper function is very straight forward and it returns what the name says… cube of 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
Why does " number % 3" set to equal 0?
For example: “if number % 3 == 0:”
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?
def cube(number) :
return number ** 3
def by_three(number) :
if number%3 == 0 :