#6 Practice makes perfect


#1



please tell me what I am missing ?
also can you tell me why
if number % and 3 == 0: does not work


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


def cube(number):
    (number) ** 3
    return number

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


#2

Line Two:
Remember to return number ** 3. :slight_smile:


#3

i thought i had with return number


#4

Yes, but that is not the multipled one.


#5

thank you
can you tell me why this was wrong
if number % 3 and == 0:


#6

Because of you are checking if number % 3 is 0.


#7

i appreciate your help:grinning:


#8

hi
(number) ** 3

it is wrong way, you have to write as follows

number ** 3


#9

Hi,

I am not sure where i am doing wrong, still getting the same error:
Oops, try again. cube(2) returned 2 instead of 8
def cube(number):
number ** 3
return number

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


#10

You have the same problem:
Remember to return number ** 3.


#11

That worked for me, thanks a lot.


#12

Hey. I'm not quite sure what I'm doing wrong here.

Oops, try again. by_three(3) returned True instead of 27

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


#14

You don't need if number ** 3: in the first function as you are not asked to test that. In the second function the return is wrong. Below if the full code:

def cube(number):
return number ** 3

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


#15

what am I doing wrong?

def cube(number):
return number ** 3

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

Oops, try again. by_three(1) returned 1 instead of False


#16

What does your second if- statement do? It should better check if number % 3 equals zero. As secondary, why does the function return the thing, that the code checks? Call to number from cube and return it.

Dear @moderators, is it possible to close the topic?


#17

thank you so much iv been stuck on this for a month now


#18

Him

My code is not working not sure what i am missing

def cube(number):
return number ** 3

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

console says
File "python", line 2
return number ** 3
^
IndentationError: expected an indented block


#19

That it:

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


#20

def cube(number):
cube=number*number*number
return cube

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

this will work


#21

you dont need to use

( number ) ** 3

you should direct write
return number ** 3

Thats it..

because its the parameter (number) which should be to the power 3 , i mean (number **3 )..

i hope this clears for you..