Practice Makes Perfect || Help please


#1



https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096#


"Oops,try again. by_three(1) returned 1 instead of False"
and
"None" in the console window


I'm not putting in a by_three(1)


def cube(number):
    return number**3
def by_three(number):
    if number % 3:
        return cube(number)
    else:
        return False


#2

That is the way that codecademy checks sometimes. It will plug numbers into your function and check the output to see if it's right. Let me ask you this though: if number % 3 == ...?


#3

Still didn't work when I put that in


#4

Don't type that exactly. I'm asking what would number % 3 be equal to if it was evenly divisible by 3? Any number divided by three with 0 left over.


#5

Not following you here. I'm piggybacking on the thread to get a hint too


#6

If we want to see if a number is evenly divisible by another number, when we divide, there will be no remainder. Since % returns the remainder from division, if we check to see if the answer is 0, then we can evenly divide it.

Example:

if 30 % 2 == 0:
    return "The number is divisible by 2 evenly. It is therefore an even number."

#7

Got it to work.
Ended up putting in:
def cube(n):
return n**3
def by_three(n):
if n % 3 == 0:
return cube(n)
else:
return False


#8

def cube(number):
result=number**3

  return result

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

else:
return False

Please help me, there's an indentation error in this code


#9

Hello

Return result needs to be under result=number**3.

I hope that helped. Try to remember that python uses indentations to put code into blocks.


#10

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