Functions and modules Flashcards
A ___________ variable is created inside a function and cannot be accessed by the statements that are outside the function.
local
insider
global
constant
local
After the Python interpreter executes the function body, ________.
it jumps to the next function in the module
it prompts the user for the next step
it terminates the program
it returns back to the calling point
it returns back to the calling point
________ provide the basic means of code reuse.
Functions
Selection structures
Sequences
Variables
Functions
The randrange function returns a randomly selected value from a specific sequence of numbers.
TRUE
FALSE
TRUE
A/an _____________ is any piece of data that is passed into a function when the function is called.
global
scope
local file
argument
argument
The first line in the function definition is known as the function __________.
header parameters block body header
header
Programmers should avoid using ______ variables in their programs when possible.
global float integer constant string
global
Different functions cannot have local variables with the same names.
TRUE
FALSE
FALSE
Python function names follow the same rules for naming variables.
TRUE
FALSE
TRUE
If a file with the specified name already exists when the file is opened and the file is opened in ‘w’ mode, then an alert will appear on the screen.
TRUE
FALSE
FALSE
Python function names follow the same rules as those for naming variables.
TRUE
FALSE
TRUE
One reason not to use global variables is that it makes a program hard to debug.
TRUE
FALSE
TRUE
In Python there is no restriction on the name of a module file.
TRUE
FALSE
FALSE
The randrange function returns a randomly selected value from a specific sequence of numbers.
TRUE
FALSE
TRUE
The math function atan(x) returns the tangent of x in radians.
TRUE
FALSE
FALSE
The _____ design technique can be used to break down an algorithm into functions.
subtask
top-down
simplification
block
top-down
A(n) _____ is a variable that receives an argument that is passed into a function.
parameter
global variable
named constant
argument
parameter
A ______ constant is a name that references a value that cannot be changed while the program runs.
string
global
local
keyword
global
A value-returning function is
called when you want the function to stop.
a single statement that performs a specific task.
a function that receives a value when called.
a function that will return a value back to the part of the program that called it.
a function that will return a value back to the part of the program that called it.
Which of the following statements causes the interpreter to load the contents of the random module into memory?
upload random
load random
download random
import random
import random
Which of the following will assign a random integer in the range of 1 through 50 to the variable number?
number = random(range(1, 50)) random(1, 50) = number number = random.randint(1, 50) randint(1, 50) = number
number = random.randint(1, 50)
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()
70 The statement will cause a syntax error. 25 100
25
Which of the following functions returns the largest integer that is less than or equal to its argument?
greater lesser ceil floor
floor
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)
Tony Gaddis Gaddis, Tony Gaddis Tony Tony, Gaddis
Gaddis, Tony
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)
9 12 Nothing, this code contains a syntax error. 14
14