ProgFund1 Exam 2
Which of the following functions returns the largest integer that is less than or equal to x?
floor
What is a group of statements that exists within a program for the purpose of performing a specific task?
function
A ________ variable is accessible to all the functions in a program file.
global
It is recommended that programmers should avoid using ________ variables in a program when possible.
global
A(n) ________ chart is also known as a structured chart.
hierarchy
In a menu-driven program, what statement is used to determine and carry out the user's desired action?
if-elif-else
Which of the following statements causes the interpreter to load the contents of the random module into memory?
import random
The ________ argument specifies which parameter the argument should be passed into.
keyword
A(n) ________ variable is created inside a function.
local
Which method could be used to convert a numeric value to a string?
str
What statement can be used to handle some of the run-time errors in a program?
try/except statement
How many types of files are there?
two
What is the result of the following statement? x=random.randint(5, 15)*2
A random integer from 5 to 15, multiplied by 2, assigned to the variable x
What type of function can be used to determine whether a number is even or odd?
Boolean
What happens when a piece of data is written to a file?
Correct Data is copied from a variable in RAM to a file.
True/False: A function definition specifies what a function does and causes the function to execute.
False
True/False: A local variable can be accessed from anywhere in the program.
False
True/False: 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.
False
True/False: In Python, there is no restriction on the name of a module file.
False
True/False: In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
False
True/False: In a menu-driven program, a loop structure is used to determine the menu item the user selected.
False
True/False: One of the drawbacks of a modularized program is that the only structure we could use is sequence structure.
False
True/False: Python allows the programmer to work with text and number files.
False
True/False: The hierarchy chart shows all the steps that are taken inside a function.
False
True/False: The value assigned to a global constant can be changed in the mainline logic.
False
True/False: Unlike other languages, in Python, the number of values a function can return is limited to one.
False
True/False: When a piece of data is read from a file, it is copied from the file into the program.
False
What makes it easier to reuse the same code in more than one program?
Modules
Which step creates a connection between a file and a program?
Open the file.
What does the following statement mean? num1, num2=get_num()
The function get_num() is expected to return a value each for num1 and num2.
True/False: A value-returning function is like a simple function except that when it finishes it returns a value back to the called part of the program.
True
True/False: An exception handler is a piece of code that is written using the try/except statement.
True
True/False: Boolean functions are useful for simplifying complex conditions that are tested in decision and repetition structures.
True
True/False: Closing a file disconnects the communication between the file and the program.
True
True/False: Different functions can have local variables with the same names.
True
True/False: If the last line in a file is not terminated with a \n, the readline method will return the line without a \n.
True
True/False: In Python, one can have a list of variables on the left side of the assignment operator.
True
True/False: It is possible to create a while loop that determines when the end of a file has been reached.
True
True/False: One of the reasons not to use global variables is that it makes a program hard to debug.
True
True/False: Python allows for passing multiple arguments to a function.
True
True/False: Python function names follow the same rules for naming variables.
True
True/False: Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.
True
True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.
True
True/False: The function header marks the beginning of the function definition.
True
True/False: The math function, ceil(x), returns the smallest integer that is greater than or equal to x.
True
True/False: The randrange function returns a randomly selected value from a specific sequence of numbers.
True
True/False: To assign a value to a global variable in a function, the global variable must first be declared in the function.
True
A value-returning function is ________.
a function that will return a value back to the part of the program that called it
A(n) ________ is any piece of data that is passed into a function when the function is called.
argument
A set of statements that belong together as a group and contribute to the function definition is known as a(n) ________.
block
Assume that the customer file references a file object, and the file was opened using the 'w' mode specifier. How would you write the string 'Mary Smith' to the file?
customer.write('Mary Smith')
When a function is called by its name, then it is ________.
executed
True/False: The math function, atan(x), returns one tangent of x in radians.
false
Which of these is associated with a specific file and provides a way for the program to work with that file?
file object
What type of value is returned by the functions random and uniform?
float
A ________ constant is a global name that references a value that cannot be changed.
global
The first line in the function definition is known as the function ________.
header
The Python library functions that are built into the Python ________ can be used by simply calling the function.
interpreter
The Python standard library's ________ module contains numerous functions that can be used in mathematical calculations.
math
Which of the following will assign a random number in the range of 1 through 50 to the variable number?
number =random.randint(1, 50)
A ________ access file is also known as a direct access file.
random
What type of file access jumps directly to any piece of data in a file without reading the data that came before it?
random
When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string?
read
What do you call the process of retrieving data from a file?
reading data
Which method will return an empty string when it has attempted to read beyond the end of a file?
readline
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.
return
Which method could be used to strip specific characters from the end of a string?
rstrip
A variable's ________ is the part of a program in which the variable may be accessed.
scope
The ________ of a local variable is the function in which the variable is created.
scope
Python comes with ________ functions that have been already prewritten for the programmer.
standard
The ________ design technique can be used to break down an algorithm into functions.
top-down
A(n) ________ is a variable that receives an argument that is passed into a function.
parameter
Which mode specifier will open a file but will not let you change the file or write to it?
'r'
Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist?
'w'
Given the following function definition, what would the statement print magic(5) display? def magic (num): return num+2*10
25