Interpreter has stopped returning my output

I’ve noticed it several lessons before this one but this is the one I’m currently on. When I hit run, it marks the question as solved but I don’t get any output. The only output I will get is if there’s an error and it will show me the error. To see the output I have to copy and paste into Jupyter. I’ve cleared my cache, restarted my computer and still the same results. It has done this on Mac and Linux PCs. Screenshot is from Jupyter showing the what should be output within the CA console.

For something to be displayed on the console (which is where the output is shown in CC lessons), it needs to be printed (using print()). When you return something, it doesn’t become output; it is simply passed back to the function’s caller, meaning it can be used by other parts of the program.

1 Like

Yes, this is why I posted the same thing from Jupyter. Both were identical. Also, it mainly only happens when calling a function. Issuing something like a straight print statement gives me output.

Indeed since none of your functions contain a print() statement, and you don’t print the output from calling them, nothing will get logged on the console/terminal, which is why there’s no output when you run it through CC.

Jupyter notebook seems to work differently, in that it’ll output the returned value from functions.


Ah, ok. I guess I had it in my head that return and print would both output to the console.

It’s a feature of many interactive Python tools to pass the evaluation of the last expression to stdout or similar (Jupyter sends it to the running notebook). You can look into it a little at-

When running a .py module normally as the lessons this hook wouldn’t be active. It’s helpful for debugging or testing things out but generally if you want to output something as part of the code your should use print or otherwise explicitly to make it happen.

It’s a good habit to get into even with interactive tools like Jupyter so you can use the same code more easily in a module. I don’t mean you should use print for every single line you run whilst you’re using Jupyter but anything like a function or more complicated section which is supposed to output something should probably be programmed to do so (rather than relying on the interactive session).

1 Like