Comments

edited by maxim-belkin

Mark Guzdial had an interesting post a few days ago on how learners with a math background may assume mistakenly that a function in programming is the same as a function in math. The exercise just asks the learner what's the output of:

This comment has been minimized.

a will be None because the function one does not return a value. Same for print.
If there is no return statement in the function code, the function ends, when the control flow reaches the end of the function body and the value "None" will be returned.

This comment has been minimized.

edited

I think the point of Mark's exercise is not so much distinguishing return vs print, but the fact that people with a mathematical background tend to assume that functions in programming are equivalent to mathematical functions. A mathematical function will map an input to an output, i.e. get some input argument and return a value (None counts as a value here).

In the exercise, people may follow this trap and say that there is only one number being printed. I think not using return and instead using print twice stresses the issue. A function returns thru one return line every time is executed, so it looks like a mathematical function, but in cases like the above we see that is actually a set of statements.

Also the value of a is not the point, in the sense that a can have only one value. The point is that two numbers are printed (I guess most people would say that here and that's why I'm saying it's easy).

But in Mark's example, you start doing the math and think that the important thing is that the value of salary changes, you only keep track of the updated value and because it really looks like a mathematical function, you may miss the first print(salary) if you have the (wrong) preconception that functions are mathematical functions.

a will be None because the function one does not return a value. Same for print.
If there is no return statement in the function code, the function ends, when the control flow reaches the end of the function body and the value "None" will be returned.

If I have the wrong idea about functions, I'm still confortable with this response because it's focusing in the point that functions take something and return something else.

To summarize, I'd say that the point of the exercise is to stress that despite functions can return things and have only one exit point (so they return one thing), they can execute arbitrary code and should not be thought of as mathematical functions.