6/19 Nothing happens!


Hi guys, please help!

I keep trying my code but absolutely nothing happens, not even an error!

def cube(number):
return number**3

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

thanks!!! (so frustrating)


You wrote the code, what’s supposed to happen when that runs?
Also note that you need to use the buttons in the editor when posting code, or you are posting something entirely different


Not sure what you mean, it should return the result or False?


Result of what? And when you say return, do you mean print?

If you have a program like this:

print 'hello world'

Then when you run it, python starts reading from the top of the file, encounters a print statement, prints the string, and then reaches past the last line and exits. A print statement was executed, therefore something was printed.

On the other hand this program:

1 + 1

Doesn’t execute a print statement, it would therefore be very surprising if anything showed up in the output.


Well, this is what the exercise says to do, it doesn’t mention Print.

Shouldn’t return be enough to ‘return’ a result?


Return has nothing to do with displaying output. It exits a function and makes a result available to the caller, similar to how how you get a result of 2 when you do 1 + 1. Wouldn’t it be annoying if + printed every time it was used? Or what if it only printed, you’d never be able to do 1 + 1 + 1 because you wouldn’t get the result of the first addition so you couldn’t add again


Not sure what to do in this case then…

This is exactly the code that worked for everyone here…(with indents of course)


Do in order to accomplish what?


return some sort of result?

Is print missing or anything else?


When you say return, do you really mean print? Because those are different things, as discussed
If you want to display output, then python does have a way of doing that, remember?
That’s the thing with programming. Programs do what you wrote. You write the program. If you don’t write it, it’s not going to happen.


Ok so I have no idea to make this code do something.


You could do some operation and print the result.

print 1 + 1

Like mentioned, python starts reading from the top, so you might compute something, and then print that something. That’s how you get something to show up in the output.

If you give Lisa a piece of paper with instructions on what to do, she’ll read from the top and work her way down, executing each thing. If that paper says:

add 1 with 1

Then she’ll probably remain silent because nowhere did she encounter

say the result out loud


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