Practice makes perfect


#1

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

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


I am new to coding and am not sure exactly what is going on. This is what I am getting"
Oops, try again. by_three(3) returned True instead of 27." I know where I want to end up for a code but am not sure how to do it. Any help would be appreciated!


#2

You wrote if number == 3: return True. The instructions say that only do this if a number is divisible by 3. Use modulo (%) instead of a comparator ==


#3

So here, according to step 4 in the instructions you are to find out "if that number is divisible by 3, " so try implementing that instead of just equaling number to 3.

as this return True is not necessary. It does not accomplish anything you are wanting to do in this lesson?


#4

I fixed it to % but it is still not working.
def cube(number):
return (number)** 3
def by_three(number):
if (number) % 3:
return True
else:
return False


#5

im with you its still not working for me


#6

Ok so for you your indentions are off. Try realigning them properly. Your return statements I believe should be one tab over under your else and if statements. And what I told mikmazey also applies to you my bad I missed that.

And @boardwhiz77040 just for future reference, I don't necessarily mind because you don't spam or interrupt the conversation but for others, if you have a question, post your own topic instead of replying to one that is already ongoing. It will save you trouble in the future on the forums :thumbsup:


#7

Not sure what was unclear about that... but here it is again


#8

I got rid of the true, I guess I put it in there because the instructions say that we need to include False. What should I return it to then, instead of True?


#9

Step 2: Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again). that should be a big enough hint xD probably too big lol


#10

I am doing that, haha.
Here is my code:
def cube(number):
return (number)** 3
def by_three(number):
if (number) % 3:
return (number)** 3
else:
return False

This is what it says:
Oops, try again. by_three(1) returned 1 instead of False


#11

Ugh I am sorry wrong part lol I confused myself hehe let me clean this up undo what I just said xD


#12

Ok, let me know! I think I understand what you're saying but something is clearly off, Sorry to bother you!


#13

No problem at all! I think I had a brain fart and I am the helper hehehe


#14

So have I done the whole problem wrong, or is it a small mistake?


#15

Ok give me a second to answer. I know what your problem is. I wasn't wrong on what I said. Your cube number section is wrong but its just the wrong way of putting it. Ok lets clear this up entirely haha


#16

Thank you! I appreciate this help.


#17

So Now, I realize you have done this and confused myself and the audience entirely. So you are technically cubing the number good job! However, for this lesson it wants you to return not the actual multiplicaton out of number being cubed but cube number. According to the correct step in step 4, "if that number is divisible by 3, by_three should call cube(number) and return its result. Otherwise, bythree should return False."

I am sorry for the confusion. I was focusing in on the wrong part of your code but I was looking at the wrong parts of the instructions to solve it. xD rookie mistake but I think this should clear all that up.


#18

So, I think I tried to do that, but I don't think I completely understand
def cube(number):
return (number)** 3
def by_three(number):
if (number) % 3:
return cube
else:
return False
and I got:
Oops, try again. by_three(1) returned instead of False


#19

Ok so your defined function is cube(number) so you have to return that fully to get the result of cubed number


#20

LOL I tried that as well,
def cube(number):
return (number)** 3
def by_three(number):
if (number) % 3:
return cube(number)
else:
return False

And got:

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