All Qu Python
All Qu Python
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?
'w'
TRUE
FALSE
FALSE