Practice Makes Perfect - Why is my code not working😞


#1



Hello,
My name is Kiran and I don't know why my code isn't working.
I have checked the hint and literally copied the code it gives me and changed the 'prints' to 'returns'- I don't think it is this the problem though, as the error message says nothing like 'Oops, did you 'print' instead of 'return'?'. I think it has something to do with the function's argument.

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



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


I would be very thankful if somebody can help me.
From Kiran


#2

On this line remove the parentheses ()

And here,

If your argument name is number use that to check if the number is divisible by three.


#3

This is the answer:

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

(It is okay if I put n. Doesn't make a difference.)

So, don't put the().

Have fun coding :smile:


#4

Many thanks! :panda_face:


#5

No problem. Happy coding :wink:


#6

That worked perfectly! Thanks candycornlover1!


#7

No problem just remember those little things can make your code go really wrong. :relaxed:


#8

Thanks I appreciate it heaps for helping me out, people like you who willing help really make a difference, I'm sure you inspire many, hope your having fun coding (and helping others code), enjoy that rest of your day (or night).:+1:


#9

No worries! Have a good day too! :slight_smile: :sunny: Or night :globe_with_meridians:


#10

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

That's what I got and it works. (You have to add the white spaces before the return on line 2, a white space before if, two whitespaces before the return on the sixth line and one whitespace before the return on the last line.


#11

Please try not to post the answer.

Steven


#12

Yeah, but I did explain what she did wrong. I just put what it has to look like.

~ Candy


#13

Aha that is true! You are right


#14

Thank you. But I should take your advice and explain more. I will do that more often.

~Candy :thumbsup:


#15

I wanted to know. Do you know what flag means? :thinking:


#16

Here look at this website. IT really helped me.


#17

thanks @candycornlover1


#18

No problem. :smiley:


#19

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.