Topic Six Flashcards
(34 cards)
Python function names follow the same rules as those for naming variables.
True or False
True
One reason not to use global variables is that it makes a program hard to debug.
True or False
True
In Python there is no restriction on the name of a module file.
True or False
False
The randrange function returns a randomly selected value from a specific sequence of numbers.
True or False
True
The math function atan(x) returns the tangent of x in radians.
True or False
False
The __________ design technique can be used to break down an algorithm into functions.
a. top-down
b. simplification
c. block
d. subtask
a. top-down
A (n) __________ is a variable that receives an argument that is passed into a function.
a. parameter
b. global variable
c. argument
d. named constant
a. parameter
A __________ constant is a name that references a value that cannot be changed while the program runs.
a. string
b. keyword
c. global
d. local
c. global
A value-returning function is ________________
a. a function that receives a value when called
b. a single statement that performs a specific task
c. called when you want the function to stop
d. a function that will return a value back to the part of the program that called it
d. 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?
a. import random
b. load random
c. upload random
d. download random
a. import random
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. number = random(range(1, 50))
d. random(1, 50) = number
a. 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()
a. The statement will cause a syntax error.
b. 25
c. 100
d. 70
b. 25
Which of the following functions returns the largest integer that is less than or equal to its argument?
a. greater
b. floor
c. ceil
d. lesser
b. 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)
a. Gaddis Tony
b. Gaddis, Tony
c. Tony, Gaddis
d. Tony Gaddis
b. 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)
a. 14
b. Nothing, this code contains a syntax error.
c. 12
d. 9
a. 14
A group of statements that exist within a program for the purpose of performing a specific task is a (n) ____________
a. block
b. parameter
c. function
d. expression
c. function
A design technique that helps to reduce the duplication of code within a program and is a benefit of using functions is ______________
a. code reuse
b. divide and conquer
c. debugging
d. facilitation of teamwork
a. code reuse
The first line of a function definition is known as the ________
a. body
b. introduction
c. initialization
d. header
d. header
You ___________ a function to execute it.
a. define
b. call
c. import
d. export
b. call
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 subtasking
a. top-down design
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
a. flowchart
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
b. local variable
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
c. scope
A (n) __________ is a piece of data that is sent into a function.
a. argument
b. parameter
c. header
d. packet
b. parameter