FAQ: Learn Python - Functions - Practice Makes Perfect

faq

#1

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 (reply) to an existing thread!

Agree with a comment or answer? Like (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!


#2

2 posts were split to a new topic: Does return do the same function as print does?


#3

A post was split to a new topic: Modulo operator


#4

2 posts were split to a new topic: “Check the console window for errors!” Error


#5

In the solution, how does:

if number % 3 == 0:

Ensure that the number is divisible by 3, and not just ensure that the number is 3? Surely if I call:

by_three(9)

The function should return False, because 9 / 3 = 3, not 0. Yet when I tried this i got 729 as an output.

There’s clearly something I’m missing surrounding the == 0 part of the code but I’m not sure what?


#6

this condition uses the modulo operator (%), which gives the remainder, which is different from division operator (/)


#7

Of course! I’m a tired idiot, thanks!


#8
def cube(number):
  return number * number * number

def by_three(number):
  number=int(raw_input ("enter a number that is divisble by three"))
  if number % 3 == 0:
    return cube(number)
  else:
    print "enter a valid number"
  by_three()

how do i make sure this loops and asks to enter valid number the get the cube