Chapter 5 Functions Flashcards
A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it.
True or False?
True
Chapter 5 Q
When a function is called by its name during the execution of a program then it is
a. located
b. exported
c. defined
d. executed
executed
Chapter 5 Q
What will display after the following code is executed?
def main(): print("The answer is", magic(5))
def magic(num): answer = num + 2 * 10 return answer
main()
a. 70
b. 25
c. 100
d. The statement will cause a syntax error.
25
Chapter 5 Q
The function header marks the beginning of the the function definition.
True or False?
True
Chapter 5 Q
It is recommended that programmers avoid using ___ variables in a program whenever possible.
a. local
b. string
c. keyword
d. global
global
Chapter 5 Q
The randrange function returns a randomly selected value from a specific sequence of numbers.
True or False?
True
Chapter 5 Q (page# 247)
The randrange function takes the same arguments as the range function. The difference is that the randrange function does not return a list of values. Instead, it returns a randomly selected value from a sequence of values
Unfortunately, there is no way to store and call on functions when using turtle graphics.
True or False?
False
Chapter 5 Q
Which of the following will assign a random integer in the range of 1 through 50 to the variable ‘number’?
a. number = random.randint(1, 50)
b. randint(1. 50) = number
c. random(1, 50) = number
d. number = random(range(1, 50)
number = random.randint(1, 50)
Chapter 5 Q
The first line in a function definition is known as the function ___
a. block
b. return
c. header
d. parameter
header
Chapter 5 Q
A set of statements that belong together as a group and contribute to the function definition is known as a ___
a. block
b. return
c. parameter
d. header
block
Chapter 5 Q
Different function can have local variables with the same names.
True or false?
True
Chapter 5 Q
What will be the output after the following code is executer?
def pass_it(x, y): z = x, ", ", y num 1 = 4 num2 = 8 answer = pass_it(num1, num2) print (answer)
a. None
b. 8, 4
c. 4, 8
d. 48
None
Chapter 5 Q
A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that calle it.
True or False?
True
Chapter 5 Q
To assign a value to a global variable in a function, the global variable must be first declared in the function.
True or False?
True
Chapter 5 Q
The randrange function returns a randomly selected value from a specific sequence of numbers.
True or False?
True
Chapter 5 Q