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

In lecture 4, when Prof Grimson adds spiders into the barnyard problem and shows us the barnyard2 and solve2 codes, I can see that solve2 doesn't have any return command. How come it runs through without any error?

OpenStudy (kizolk):

You don't actually *need* a return statement for a function to work. The simplest function you can define does nothing at all actually, for instance: def function(): pass (the "pass" keyword is used for syntactical purposes; it does precisely nothing, but you still need it in this case because a function definition needs to have a body) You could call this function, and it would be executed without any error, but it'd do nothing. Going back to prof Grimson's function: it still is useful because it prints out the answer. You couldn't do something with it (for instance assigning the result to a avariable and do something with it), but it still gives you the right answer, so it's ok.

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!