python final - quiz review
In Python the ________ symbol is used as the not-equal-to operator.
!=
Which mode specifier will open a file but 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 the file if it does NOT already exist?
'w'
Which method or operator can be used to concatenate lists?
+
What is the output of the following code? val = 123456.789 print(f'{val:,.2f}')
123,456.79
What will display after the following code is executed after the "The answer is"?
25
After the execution of the following statement, the variable price will reference the value price = int(68.549)
68
In Python the ________ symbol is used as the equality operator.
==
What type of function can be used to determine whether a number is even or odd?
Boolean
According to the behavior of integer division, when an integer is divided by an integer, the result will be a float.
False
Arrays, which are allowed by most other programming languages, have more capabilities than Python list structures.
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
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
Python allows the programmer to work with text and number files.
False
Python formats all floating-point numbers to two decimal places when outputting with the printstatement.
False
Short -circuit evaluation is only performed with the not operator.
False
Since a named constant is just a variable, it can change any time during a program's execution.
False
The Python language is not sensitive to block structuring of code.
False
The index of the first element in a list is 1, the index of the second element is 2, and so forth.
False
The remove method removes all occurrences of an item from a list.
False
The strip() method returns a copy of the string with all the leading whitespace characters removed but does not remove trailing whitespace characters.
False
Unlike other languages, in Python the number of values a function can return is limited to one.
False
What is the result of the following Boolean expression, given that x = 5, y = 3, and z= 8? not (x < y or z > x) and y < z
False
When a piece of data is read from a file, it is copied from the file into the program.
False
What will be the output after the following code is executed?
Smith, Julian
A flowchart is a tool used by programmers to design programs.
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
An action in a single alternative decision structure is performed only when the condition is true.
True
An exception handler is a piece of code that is written using the try/except statement.
True
Comments in Python begin with the # character.
True
Computer programs typically perform three steps: input is received, some process is performed on the input, and output is produced.
True
Decision structures are also known as selection structures.
True
Expressions that are tested by the if statement are called Boolean expressions.
True
In Python, print statements written on separate lines do not necessarily output on separate lines.
True
In order to create graphs using the matplotlibpackage, you need to import the pyplot module.
True
In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.
True
Invalid indexes do not cause slicing expressions to raise an exception.
True
It is possible to create a while loop that determines when the end of a file has been reached.
True
Lists are dynamic data structures such that items may be added to them or removed from them.
True
Nested decision statements are one way to test more than one condition.
True
Python allows programmers to break a statement into multiple lines.
True
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
The ZeroDivisionError exception is raised when the program attempts to perform the calculation x/y if y = 0.
True
The \t escape character causes the output to skip over to the next horizontal tab.
True
The function header marks the beginning of the function definition.
True
The if statement causes one or more statements to execute only when a Boolean expression is true.
True
The index -1 identifies the last element in a list.
True
To assign a value to a global variable in a function, the global variable must be first declared in the function.
True
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y or z > x
True
When using the camelCase naming convention, the first word of the variable name is written in lowercase and the first characters of all subsequent words are written in uppercase.
True
Which list will be referenced by the variable number after the following code is executed? number = range(0, 9, 2)
[0, 2, 4, 6, 8]
What will be the value of the variable list after the following code executes? list = [1, 2] list = list * 3
[1, 2, 1, 2, 1, 2]
What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[3] = 10
[1, 2, 3, 10]
What will be the value of the variable list2 after the following code executes? CH7
[1, 2, 3]
The line continuation character is a
\
What symbol is used to mark the beginning and end of a string?
a quote mark (")
Which statement can be used to handle some of the runtime errors in a program?
a try/except statement
1 / 1 pts A set of statements that belong together as a group and contribute to the function definition is known as a
block
This function in the random module returns multiple, nonduplicated random elements from a list.
choices
Multiple Boolean expressions can be combined by using a logical operator to create ________ expressions.
compound
A(n) ________ structure is a logical design that controls the order in which a set of statements execute.
control
Given 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')
The decision structure that has two possible paths of execution is known as
dual alternative
What are the data items in a list called?
elements
In a print statement, you can set the ________ argument to a space or empty string to stop the output from advancing to a new line.
end
Python uses the same symbols for the assignment operator as for the equality operator.
false
A single piece of data within a record is called a
field
After the execution of the following statement, the variable sold will reference the numeric literal value as (n) ________ data type. sold = 256.752
float
A(n) ________ is a diagram that graphically depicts the steps that take place in a program.
flowchart
A ________ constant is a name that references a value that cannot be changed while the program runs.
global
A ________ variable is accessible to all the functions in a program file.
global
It is recommended that programmers avoid using ________ variables in a program whenever possible.
global
The first line in a function definition is known as the function
header
Which of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive?
if y >=10 and y <=50
The ________ function reads a piece of data that has been entered at the keyboard and returns that piece of data, as a string, back to the program.
input()
Which method can be used to place an item at a specific index in a list?
insert
The Python library functions that are built into the Python ________ can be used by simply calling the required function.
interpreter
Which method can be used to convert a tuple to a list?
list
A ________ variable is created inside a function.
local
What will be the output after the following code is executed? CH5
none
The not operator is a unary operator which must be used in a compound expression.
not
Which logical operators perform short-circuit evaluation?
not, and
What will be the output after the following code is executed? CH7
nothing; the number of x-coordinates do not match the number of y-coorindates
Which step creates a connection between a file and a program?
open the file
When using the ________ logical operator, one or both of the subexpressions must be true for the compound expression to be true.
or
Which of the following is the correct way to open a file named users.txt to write to it?
outfile = open('users.txt', 'w')
The ________ keyword is ignored by the Python interpreter and can be used as a placeholder for code that will be written later.
pass
Which of the following will display 20%?
print(f'{0.2:.0%}')
What is an advantage of using a tuple rather than a list?
processing a tuple is faster than processing a list
A(n) ________ access file is also known as a direct access file.
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 is the process of retrieving data from a file called?
reading data
Which method will return an empty string when it has attempted to read beyond the end of a file?
readline
Python comes with ________ functions that have already been prewritten for the programmer.
standard
Which method could be used to convert a numeric value to a string?
str
Which of the following is associated with a specific file and provides a way for the program to work with that file?
the file object
What does the following statement mean? num1, num2 = get_num()
the function get_num() is expected to return a value for num1 for num2
The ________ design technique can be used to break down an algorithm into functions.
top-down
A Boolean variable can reference one of two values which are:
true or false
Which method can be used to convert a list to a tuple?
tuple