Practise makes perfect


#1



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

Oops, try again. cube(1) returned 2 instead of 1


Replace this line with your code. 
def cube(number):
    return number^3
def by_three(number):
    if number%3==0:
        return cube(number)
    else:
        return False


#2

To multiply by powers it is
**

Not,
^


#3

All good except for this:

Raising a number to a power is done using **.

See full below

def cube(number): #cube function with number parameter
    return number**3 #returns cube of number
    
def by_three(number):
    if number % 3 == 0:
        return cube(number)
    
    else:
        return False

#4

ah thanks guys, lol silly me


#5

@ bayoishola20 i have the exact same code:

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

here is your code:
def cube(number):
return number**3
def by_three(number):
if number % 3 == 0:
return cube(number)
else:
return False

it says my code is wrong?? HELP!!


#6

you are missing the : after your "if number % 3==0" and "else"


#7

I would have loved you format your code since this language is indentation sensitive.

Well, we do not have exactly the same code.

Here,

Where as mine is:

Observe that you missed the colon after else and that will affect indentation. Also, it is False and not false.


#8

does anyone know why on line 4:

if number%3==0

has to be equaled to 0?

Is it because then it is false?
when i didn't add the 0 it said it comes out as 1 instead of false.


#9

the return false is wrong it's supposed to be False not false


#10

or you can do this

def cube(number):
return number * number * number # it is slow than #number**number

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


#11

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