Practice leads to perfection


#1

Good Morning.

I've been stuck in this lesson for an hour and so far I have not been able to figure out what it is you have to do.

def cube(number):
    return number**number

def by_three(number):
    if cube(number) / 3 :
        return cumber(number)
    else:
        return "False"
by_three(number);

Error message: Oops, try again. Did you create a function called "by_three"?


#2

here:

if cube(number) / 3 :

cube(number) is a function call, calling the function inside the function is called recursion. The way you coded it, its sort of like an infinity loop (but then with functions/recursion)

to check if the number is divisible by three, you need to check if the remainder equals zero. We can do this using modulo operator (%)

then when you call the function on the last line:

by_three(number)

supply an actual number (27 for example)

and here:

return cumber(number)

you misspelled cube


#3

So should I call the if function like this?

def by_three(number):
    if number / 3% == 0:

#4

better, i don't see why you need the division operator (/)? number % 3 will gives you the remainder


#5

Like this?

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

#6

better, but why did you change return cumber(number)? Apart from the fact that you misspelled cube, you need to return cube of number if number is divisible by 3.

and if not divisible return False (boolean value, not string)


#7

Yeah, I still can not... :confused:

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

#8

here:

return = False

why a equal sign between return and False? can i see your full code, make sure you didn't mess up your cube function

Do you even understand what you are doing? It feels like you are just trying


#9

def cube(number):
    return number**number

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

Error message: Oops, try again. Its cube function returns 46656 with input 6 when it should return 216. Make sure it returns the number raised to the cube.


#10

the cube of a number is to the power of 3 (^3):

1 ^ 3 = 1
2 ^ 3 = 8
3 ^ 3 = 27

you do the number to the power of number

I used math syntax (^) in the example, make sure use python syntax (**) for to the power


#11

I know power. I'm not understanding the code '-'
If it's for me to put 3**3 where do I have to put that power, then? In place of "number ** number" I put "3 ** 3" ?


#12

math syntax:

2 ^ 3

python syntax:

2 ** 3

both is 2 to the power of 3 (resulting in 8)


#13

Yes I understand.

I want to know where I'm going to use power in my code outside " number**number "?


#14

but you should get the cube (to power of 3) of number. I don't understand the question


#15

This is occurring because I am not understanding your instructions very well. I always do not understand.


#16

How should my instructions be then? Many people understand them perfectly, i have helped a lot of people solve there problem


#17

Your instruction is good, I did not say otherwise.
However, the course instruction translated into Brazilian Portuguese is very vague and almost meaningless. So your instructions are confusing to me in the same way that my explanations are confusing for you.

You see ?


#18

well, then i can't help you. You will need to make topics on the Portuguese forum section, in the hope that someone can help you there.

There you are allowed to ask questions not in English.

Or you should do the English course to improve your english


#19

Aaaaaaaaaaaaaaaaahhhh .... I thought that there was no longer the forum area in Portuguese. Excuse me. Is that before it was easier to find the forum in Portuguese.

I am sorry for the inconvenience.

And yes, I study English, only that, my writing, is my weak point. I know how to speak more than write.
I'm sorry and you can close the topic. Thank you very much.


#20

Kimo,

I think the issue is with your cube function. Above you say the cube function is

def cube(number):
    return number ** number

What you should be doing is taking the number to the power of 3 which looks like this

def cube(number):
    return number ** 3

The issue is that when you run your cube code, it takes the number to the power of the same number, for example:

cube(2) in your code will return 2 ** 2 = 4
cube(2) in the corrected code I show above will return 2 ** 3 = 8

Does this help?

When you run the code you enter a value for the variable number, and take it to the 3rd power. In your code, you enter a value for the number, and take it to the 'number' power.