Chapter 6
Contents: True/False | Multiple Choice | Discussion
| Programs
True/False
- False
- False
- True
- True (None is returned when no explicit value is provided)
- False (Technically, all are passed by value, but those value may be
mutable)
- False
- False (Mutable parameters can be changed)
- True
- True
- False
Multiple Choice
- b
- a
- a
- b
- d
- a
- d
- a
- d
- a
Discussion
- The two main motivations are reducing
duplication and making the code ore modular. These can be described in a
variety of ways.
- Both the calling code and the function definition itself can
be thought of as sequential. Although the program now seems to "jump around"
to execute various function definitions, each part can still be considered
as sequential. This is a good springboard for discussing levels of abstraction.
-
- The main purpose is to provide information from the caller to the
function. Parameters provide the changeable context of a function call.
- Formal parameters are variables in the function definition. Actual
parameters are the values given to those variables when control transfers
to the function.
- Parameters are like ordinary function variables in that they are
local to the function and serve as "name values." They are different because
they are automatically assigned an initial value when the function is called.
Normal local variables have to be assigned a value within the function definition.
-
- Parameters can be used as input to the function.
- Usually through a return statement. Functions may also change the
values of mutable parameters.
-
- Returns the cube of its argument.
- cube(y)
- There are two different variables named answer. The variable inside
of cube is changed, but it does not affect the value of the other variable.
Programming Exercises
Code for Chapter 6 Exercises