I don't understand what's wrong with my code | Practice Makes Perfect


#1


I dont know why it won't work


def cube(number): 
    return number ** 3

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

i have no errors in the console apart from it displaying "none"

but codecademy's notification says "Oops, try again. by_three(1) returned 1 instead of False"

please tell me what's wrong with it


#2

Then what happens? By your statement, the codes just has to make sure that the number can be divided by three, which all numbers can be divided. What you should be asking is if it is divisible by 3. I'm sure you can figure out your mistake now. If not message me and I'll help. :slight_smile:


#3

Haha sorry xP , I still don't understand


#4

It's okay and you will understand it as long as you have done 3rd grade math. It's a simple error really. When you are saying:

It doesn't do much. The percentage sign in there is modulus(I assume you known that taken that you have done the other Codecademy courses on Python). It gives you the remainder when dividing a number, and is quite useful for divisibility( hint, hint). In this case it's going to be the remainder of dividing our variable number by 3.

Now your problem comes from not writing the entire equation using modulus. We want to make sure that the if statement only happens if the number is divisible by 3, not otherwise. Right now what you have is the remainder from dividing it by three. But we want to make sure that the remainder is equal to 0 (hint again), becuase then we known it is divisible by three. So, think about what you could add to your if statement to make that happen. I appreciate you asking for help and trying to learn instead of simply asking for the answer. Good job. :slight_smile:


#5

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