Practice Makes Perfect


#1

def cube(number):
return number **3

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

I cant figure out what is wrong. Plz help.


#2

4. if that number is divisible by 3,
-> If it is divisible by 3, the result would be 0 (number % 3), right? But 0 is False and 1 is True in python, so you have to do it this way, that it actually takes this route if it is divisible by 3:

if number % 3 == 0

or

if not number % 3:

Second issue is:

You have to return the value, or your function will return None, if it is divisible by 3

return cube(number)

Hope it helps :grin:


#3

Thank you, It did help :slightly_smiling:


#4

This is the correct answer:
def cube(number):
return number **3

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


#5

Hi
I have this code - and it does not work

f cube(number):
return number**3

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


#6

it start with def and not just f ;O)


#7

I finally got it to work using this

def cube(number):
return number ** 3

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

make sure your indentations are correct. I had the code correct for over an hour and kept getting an error due to the return line not being indented