Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 17 Online
OpenStudy (anonymous):

I've tried to run a few programs from the PDFs and from the web, but find that they don't return any values. What gives?

OpenStudy (anonymous):

I sometimes copy the code verbatim, when I run the programs, they won't return any value for me.

OpenStudy (anonymous):

Which pdfs are you talking about?

OpenStudy (anonymous):

I'm making a lot of assumptions here. 1. You're using IDLE. 2. You run the code you're editing by hitting F5 (Run Module). 3. When you say "return a value" you mean the module doesn't do anything when you run it. 4. The PDFs are the handouts from the lectures, or maybe the skeleton code they provided for some problem sets. When you run a module it executes all the statements in the modules. If the only statements are function definitions, then there won't be any output. If some statements exist outside the function statements, those will run and (maybe) produce some output. If the module defines functions, but doesn't have a statement that calls one of them, nothing will happen. What you should do is run the module to get the functions loaded in the shell, then use the interactive shell to call the function you want to run. That's easier than putting a function call in the module, then editing it every time you want to test some different parameters. Also, it allows you to load the functions without executing anything, in case you just want to load the functions. The other possibility is that all the code in the file is commented out. The professors prepared a code file that they would run during the lectures, but they only wanted to run a small portion at a time. So they would comment out everything, then uncomment just the thing they wanted to run. Then comment that out and uncomment the next thing. Etc. So you'd have to uncomment the part you want to run. You can highlight several lines and do Format->Uncomment Region or Comment Out Region to do that in bulk. And the skeleton code for the problem sets generally has empty functions that you're supposed to fill in. Also, they generally only have function definitions, so you can pick which function to run from the shell, instead of something running automatically.

OpenStudy (anonymous):

make sure you have return statements in your functions http://codepad.org/hgW514Hc

OpenStudy (anonymous):

I'm actually using a linux machine with terminal and gedit. It just sometimes seems to be ignoring the return function...

OpenStudy (anonymous):

as for pdfs, the exam, and the lecture

OpenStudy (anonymous):

Jwalker, use codepad or something to post the offending functions please.

OpenStudy (anonymous):

http://codepad.org/BuYgfqsf

OpenStudy (anonymous):

http://codepad.org/vvUUGU5R

OpenStudy (anonymous):

Those are just function definitions. To make something happen you have to call the functions. You can do that after you load the module into the shell, or add code to the module itself that will call the functions. For example: compare1(0, 3) compare1(-3, 3)

OpenStudy (anonymous):

Thanks. I wonder if they had access to computers during the exams

OpenStudy (anonymous):

Almost certainly not. Actually, I wonder if the professors did when they were writing the answers to quiz2. Their answer to problem 6 is pretty convoluted, and doesn't even work.

OpenStudy (anonymous):

Well, this is more of an academic class, not a practical one. So I think that the ideas are a lot more important than the application. I go for the application a lot more than academics, but that's just me.

OpenStudy (anonymous):

Not to go on about this, but I hope those profs weren't expecting students to memorize code.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!