Chapter 5 multiple choice
Python comes with __________ functions that have already been prewritten for the programmer. a. standard b. library c. custom d. key
A
The Python standard library's __________ module contains numerous functions that can be used in mathematical calculations. a. math b. string c. random d. number
A
The first line in a function definition is known as the function a. header b. block c. return d. parameter
A
What does the following statement mean? num1, num2 = get_num() a. The function get_num() is expected to return a value for num1 and for num2. b. The function get_num() is expected to return one value and assign it to num1 and num2. c. This statement will cause a syntax error. d. The function get_num() will receive the values stored in num1 and num2.
A
What is a group of statements that exists within a program for the purpose of performing a specific task? a. a function b. a subtask c. a process d. a subprocess
A
When a function is called by its name during the execution of a program, then it is a. executed b. located c. defined d. exported
A
Which of the following functions returns the largest integer that is less than or equal to its argument? a. floor b. ceil c. lesser d. greater
A
A set of statements that belong together as a group and contribute to the function definition is known as a a. header b. block c. return d. parameter
B
A(n) __________ is any piece of data that is passed into a function when the function is called. a. global variable b. argument c. local variable d. parameter
B
It is recommended that programmers avoid using __________ variables in a program whenever possible. a. local b. global c. string d. keyword
B
What does the following program do? import turtle def main(): turtle.hideturtle() square(100,0,50,'blue') def square(x, y, width, color): turtle.penup() turtle.goto(x, y) turtle.fillcolor(color) turtle.pendown() turtle.begin_fill() for count in range(2): turtle.forward(width) turtle.left(90) turtle.end_fill() main() a. It draws a blue square. b. It draws a blue triangle. c. It draws 2 blue lines. d. Nothing since you cannot call a function with turtle graphics.
B
What will be the output after the following code is executed? def pass_it(x, y): z = y**x return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer) a. 81 b. 64 c. 12 d. None
B
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.
B
Which of the following statements causes the interpreter to load the contents of the random module into memory? a. load random b. import random c. upload random d. download random
B
Which of the following will assign a random integer in the range of 1 through 50 to the variable number? a. random(1, 50) = number b. number = random.randint(1, 50) c. randint(1, 50) = number d. number = random(range(1, 50))
B
A __________ constant is a name that references a value that cannot be changed while the program runs. a. keyword b. local c. global d. string
C
A __________ variable is accessible to all the functions in a program file. a. keyword b. local c. global d. string
C
A value-returning function is a. a single statement that performs a specific task b. called when you want the function to stop c. a function that will return a value back to the part of the program that called it d. a function that receives a value when called
C
A(n) __________ chart is also known as a structured chart. a. flow b. data c. hierarchy d. organizational
C
The __________ design technique can be used to break down an algorithm into functions. a. subtask b. block c. top-down d. simplification
C
What does the following program do? import turtle def main(): turtle.hideturtle() square(100,0,50,'blue') def square(x, y, width, color): turtle.penup() turtle.goto(x, y) turtle.fillcolor(color) turtle.pendown() turtle.begin_fill() for count in range(4): turtle.forward(width) turtle.left(90) turtle.end_fill() main() a. It draws a blue square at coordinates (100, 0), 50 pixels wide, starting at the top right corner. b. It draws a blue square at coordinates (0, 50), 100 pixels wide, starting at the top right corner. c. It draws a blue square at coordinates (100, 0), 50 pixels wide, in the lower-left corner. d. Nothing since you cannot call a function with turtle graphics.
C
What will be displayed after the following code is executed? def pass_it(x, y): z = x*y result = get_result(z) return(result) def get_result(number): z = number + 2 return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer) a. 12 b. 9 c. 14 d. Nothing, this code contains a syntax error.
C
A __________ variable is created inside a function. a. global b. constant c. named constant d. local
D
A(n) __________ is a variable that receives an argument that is passed into a function. a. global variable b. argument c. named constant d. parameter
D
In a value-returning function, the value of the expression that follows the keyword __________ will be sent back to the part of the program that called the function. a. def b. result c. sent d. return
D
The Python library functions that are built into the Python __________ can be used by simply calling the required function. a. code b. compiler c. linker d. interpreter
D
The __________ of a local variable is the function in which that variable is created. a. global reach b. definition c. space d. scope
D
What type of function can be used to determine whether a number is even or odd? a. even b. odd c. math d. Boolean
D
What will be the output after the following code is executed? def pass_it(x, y): z = x + ", " + y return(z) name2 = "Tony" name1 = "Gaddis" fullname = pass_it(name1, name2) print(fullname) a. Tony Gaddis b. Gaddis Tony c. Tony, Gaddis d. Gaddis, Tony
D
What will be the output after the following code is executed? def pass_it(x, y): z = x , ", " , y num1 = 4 num2 = 8 answer = pass_it(num1, num2) print(answer) a. 4, 8 b. 8, 4 c. 48 d. None
D