Week 5 Flashcards
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. a function
The first line in a function definition is known as the function
a. header
b. block
c. return
d. parameter
a. header
The __________ design technique can be used to break down an algorithm into functions.
a. subtask
b. block
c. top-down
d. simplification
c. top-down
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. block
A(n) __________ chart is also known as a structured chart.
a. flow
b. data
c. hierarchy
d. organizational
c. hierarchy
A __________ variable is created inside a function.
a. global
b. constant
c. named constant
d. local
d. local
The __________ of a local variable is the function in which that variable is created.
a. global reach
b. definition
c. space
d. scope
d. scope
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. argument
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. parameter
A __________ variable is accessible to all the functions in a program file.
a. keyword
b. local
c. global
d. string
c. global
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. global
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
executed
It is recommended that programmers avoid using __________ variables in a program whenever possible.
a. local
b. global
c. string
d. keyword
b. global
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. interpreter
Python comes with __________ functions that have already been prewritten for the programmer.
a. standard
b. library
c. custom
d. key
b. library/standard???
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. Boolean
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 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. load random
b. import random
c. upload random
d. download random
b. import random
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. number = random.randint(1, 50)
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. The function get_num() is expected to return a value for num1 and for num2.
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. 25
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. return
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. math
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. 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)
Gaddis, Tony
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)
None
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)
64
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)
14
Python function names follow the same rules as those for naming variables.
True
The function header marks the beginning of the function definition.
True
A function definition specifies what a function does and causes the function to execute.
False
A hierarchy chart shows all the steps that are taken inside a function.
False
A local variable can be accessed from anywhere in the program.
False
Different functions can have local variables with the same names.
True
Python allows you to pass multiple arguments to a function.
Python
To assign a value to a global variable in a function, the global variable must be first declared in the function.
True
The value assigned to a global constant can be changed in the mainline logic.
False
One reason not to use global variables is that it makes a program hard to debug.
True
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
Unlike other languages, in Python the number of values a function can return is limited to one.
False
In Python you can have a list of variables on the left side of the argument operator.
True
In Python there is no restriction on the name of a module file.
False
One of the drawbacks of a modularized program is that the only structure you can use in such a program is the sequence structure.
False
One reason to store graphics functions in a module is so that you can import the module into any program that needs to use those functions.
True
The randrange function returns a randomly selected value from a specific sequence of numbers.
True
The math function atan(x) returns one tangent of x in radians.
False
The math function ceil(x) returns the smallest integer that is greater than or equal to x.
True
The code for a function is known as a function ___________.
definition
The function header begins with the keyword __________ and is followed by the name of the function.
def
The main function contains a program’s __________ logic which is the overall logic of the program.
mainline
In a flowchart, a function call is depicted by a(n) ___________.
rectangle
The top-down design breaks down the overall task of a program into a series of __________.
subtasks
A(n) __________ chart is a visual representation of the relationships between functions.
hierarchy
Arguments are passed by __________ to the corresponding parameter variables in a function.
position
A variable is available only to statements in the variable’s __________.
scope
Functions that are in the standard library are stored in files that are known as __________.
modules
To refer to a function in a module, Python uses ___________ notation.
dot
A value-returning function has a(n) ___________ statement that sends a value back to the part of the program that called it.
return
The ___________ chart is an effective tool used by programmers to design and document functions.
IPO
The ‘P’ in the acronym IPO refers to ___________.
Processing
In Python, a module’s file name should end in ___________.
.py
The approach known as __________ makes a program easier to understand, test, and maintain.
Modularization
The return values of the trigonometric functions in Python are in __________.
Radians
The term _______________ is used to describe any mechanism that accepts input, performs some operation that cannot be seen, and produces output.
Black Box
In a menu-driven program, a loop structure is used to determine the menu item the user selected.
False
In a menu-driven program, a loop structure is used to determine the menu item the user selected.
False