Practice makes perfect. help me!


#1

Does anyone know how the code on Part 6 of Functions is supposed to work? Here is my code:

def cube(n):
    return n * n * n

def by_three(n):
    if n % 3 == 0:
        return by_three(n)
    print "divisible by three"
else:
        return False
    print "not divisible by three"

#2

This is an opportunity to try out the exponent operator, **.

    return n ** 3

Anything after return is unreachable so this will not print. The line may be removed since it is not asked for.

        return by_three(n)

causes an infinite loop. Change it to call the cube() function.

        return cube(n)

    else:
        return False

#3

On this line:

Do it like this:

n**3

The ** operator in python is exponent,it is an operator that performs exponential (power) calculation on operators
meaning we read n**3 as n cube or n to the power of three

One more thing:

As the instruction says in number 4: if that number is divisible by 3, by_three should call cube(number) and return its result, your by_three function should return cube(n) if n is divisible by 3


#4

Here is my code and it keeps telling that by_three(3) returns true instead of 27 what am I doing wrong?

def cube(n):
return n**3

def by_three(n):
if n % 3 == 0:
return True

else:
    return False

#5

I suggest making your own topic. Please do not revive 9 month old ones. :slight_smile: We want to help you the best way we can, so a new topic could be the best bet for you.


#6

I did not know how to make my own topic. How do I do so?


#7

You can go to the main page, and in the top right corner, click new topic. :slight_smile:


#8

def cube(number):
return number**3

def by_three(number):
if number % 3 == 0:
return number**3
else:
return False[/details]