0% found this document useful (0 votes)
22 views

All Qu Python

The document discusses code reuse through functions. It provides a set of review questions about functions covering topics like defining and calling functions, parameters, arguments, local and global variables, and standard library functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

All Qu Python

The document discusses code reuse through functions. It provides a set of review questions about functions covering topics like defining and calling functions, parameters, arguments, local and global variables, and standard library functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

code reuse

298 Chapter 5 Functions

4. You __________ a function to execute it.


a. define
b. call
c. import
d. export
5. A design technique that programmers use to break down an algorithm into functions is known
as __________.
a. top-down design
b. code simplification
c. code refactoring
d. hierarchical sub tasking
6. A __________ is a diagram that gives a visual representation of the relationships between
functions in a program.
a. flowchart
b. function relationship chart
c. symbol chart
d. hierarchy chart
7. A __________ is a variable that is created inside a function.
a. global variable
b. local variable
c. hidden variable
d. none of the above; you cannot create a variable inside a function
8. A(n) __________ is the part of a program in which a variable may be accessed. a.
declaration space
b. area of visibility
c. scope
d. mode
9. A(n) __________ is a piece of data that is sent into a function.
a. argument
b. parameter
c. header
d. packet
10. A(n) __________ is a special variable that receives a piece of data when a function is called.
a. argument
b. parameter
c. header
d. packet
11. A variable that is visible to every function in a program file is a __________.
a. local variable
b. universal variable
c. program-wide variable
d. global variable
Review Questions 299
12. When possible, you should avoid using __________ variables in a program. a. local
b. global
c. reference
d. parameter
13. This is a prewritten function that is built into a programming language.
a. standard function
b. library function
c. custom function
d. cafeteria function
14. This standard library function returns a random integer within a specified range of values.
a. random
b. randint
c. random_integer
d. uniform
15. This standard library function returns a random floating-point number in the range of 0.0 up
to 1.0 (but not including 1.0).
a. random
b. randint
c. random_integer
d. uniform
16. This standard library function returns a random floating-point number within a specified
range of values. a. random
b. randint
c. random_integer
d. uniform
17. This statement causes a function to end and sends a value back to the part of the program
that called the function. a. end
b. send
c. exit
d. return
18. This is a design tool that describes the input, processing, and output of a function. a. hierarchy
chart
b. IPO chart
c. datagram chart
d. data processing chart
19. This type of function returns either True or False.
a. Binary
b. true_false
c. Boolean
d. logical
300 Chapter 5 Functions

20. This is a math module function.


a. derivative
b. factor
c. sqrt
d. differentiate
True or False
1. The phrase “divide and conquer” means that all of the programmers on a team should be
divided and work in isolationF
2. Functions make it easier for programmers to work in teams. T
3. Function names should be as short as possible. F
4. Calling a function and defining a function mean the same thing. F
5. A flowchart shows the hierarchical relationships between functions in a program.F
6. A hierarchy chart does not show the steps that are taken inside a function.T
7. A statement in one function can access a local variable in another function.F
8. In Python, you cannot write functions that accept multiple arguments.F
9. In Python, you can specify which parameter an argument should be passed into a function call.
T
10. You cannot have both keyword arguments and non-keyword arguments in a function call.F
11. Some library functions are built into the Python interpreter.T
12. You do not need to have an import statement in a program to use the functions in the random
module.F
13. Complex mathematical expressions can sometimes be simplified by breaking out part of the
expression and putting it in a function. T
14. A function in Python can return more than one value.T
15. IPO charts provide only brief descriptions of a function’s input, processing, and output, but do
not show the specific steps taken in a function. T

Short Answer
1. How do functions help facilitate teamwork?
Functions help you reuse code in a program because the function can be written once to
perform an operation, and then be executed any time it is needed.
2. Name and describe the two parts of a function definition.
The two parts of a function definition are known as a function header and a block. The
header marks the beginning of the function definition and begins with the keyword 'def'
followed by the name of the function, followed by a set of parenthesis, and followed by
a colon. The block is a set of statements that belong together as a group, and are
performed any time the function is executed.
3. When a function is executing, what happens when the end of the function block is reached?
When a function is executing, it 'returns' when the end of the block is reached - meaning the
interpreter jumps back to the part of the program that called the function, and the program
resumes execution at that point.
4. What is a local variable? What statements are able to access a local variable?
A local variable is a variable that is declared inside of a function. Only statements in the same
function can access a local variable.
5. What scope do parameter variables have?
A parameter variable’s scope is the function in which the parameter is used.
6. Why do global variables make a program difficult to debug?
Because any statement in a program file can change the value of a global variable
7. Suppose you want to select a random number from the following sequence:
0, 5, 10, 15, 20, 25, 30
What library function would you use?
randrange
ex: num = random.randrange(0, 5, 10, 15, 20, 25, 30)
8. What statement do you have to have in a value-returning function?
return expression,
where expression holds the value that is to be returned to the calling function.
9. Draw an IPO chart that documents the input, processing, and output of the built-in input
function.
10. What is a Boolean function?

a function which returns either True or False.


11. What are the advantages of breaking a large program into modules?
run/handle
try/except
try/handle
attempt/except

'w'
TRUE

FALSE

FALSE

except try/except TRUE


try/except
FALSE
try/except
FALSE

You might also like