There is a pre-publication version of this book available for free download. However, it is not as complete as the published version.
Reading Questions. Provide answers to the following two questions on a Portfolio page for this reading assignment.
# Comment: Figure out what this function does
# Notice how we put the parameters, X and Y, in a list enclosed in parentheses
# Notice that a function definition ends with a Return statement
To mysteryFunction(X, Y):
Let S be 0
While X <= Y do:
Let S be S + X
Let X be X + 1
Return S
What value would this function return if it is called with mysteryFunction(1, 5)? Note: The convention here is that the value 1 would be substituted for the parameter X and the value 5 would be substituted for the parameter Y. Given that convention, trace the code to figure out the result. In general what does this function compute?
# Comment: Figure out what this function does
# Notice that the parameter list is empty in this case
To computeSomething():
Let P be 1
Let N be 4
While N >= 1 do:
Let P be P * N
Let N be N - 1
Return P
What value would this function return when it is called with computeSomething()? In general what does this function compute? How would you modify this function, using a parameter, to make it more general?