Programming Final
A function definition specifies what a function does and causes the function to execute.
False
A local variable can be accessed from anywhere in the program.
False
According to the behavior of integer division, when an integer is divided by an integer, the result will be a float.
False
In Python, a list may contain objects of any type but they must all be of the same type.
False
In Python, an infinite loop usually occurs when the computer accesses an incorrect memory address.
False
Python allows you to compare strings, but it is not case sensitive.
False
Python uses the same symbols for the assignment operator as for the equality operator.
False
Short circuit evaluation is only performed with the not operator.
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 not operator is a unary operator which must be used in a compound expression.
False
The remove method removes all occurrences of an item from a list.
False
What will be displayed after the following code is executed? for num in range(0, 20, 5): num += num print(num)
30 *because expanded range is (5, 10, 15) which adds to 30
What will be displayed after the following code is executed? total = 0 for count in range(4,6): total += count print(total)
4 9 *because expanded range is (4, 5) which adds to 9 IDK WHERE THE 4 CAME FROM???? TF
What will be displayed after the following code is executed? total = 0 for count in range(1,4): total += count print(total)
6 *because expanded range is (1,2,3) which adds to 6
The sort method rearranges the elements of a list so they are in ascending or descending order.
False
Tuples cannot be sliced.
False
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y and z > x
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
The first line in a while loop is referred to as the condition clause.
False *its actually a for-loop header
A(n) ________ is a variable that receives an argument that is passed into a function.
parameter
What is the informal language, used by programmers use to create models of programs, that has no syntax rules and is not meant to be compiled or executed?
pseudocode
What is the process of retrieving data from a file called?
reading data
The primary difference between a tuple and a list is that
once a tuple is created, it cannot be changed
When using the ________ logical operator, one or both of the subexpressions must be true for the compound expression to be true.
or
What is an advantage of using a tuple rather than a list?
Processing a tuple is faster than processing a list.
The ________ function can be used to convert a list to a tuple.
Tuple
A ________ variable is created inside a function.
local
The ________ function returns the item that has the lowest value in the sequence.
min
What is a group of statements that exists within a program for the purpose of performing a specific task?
a function
A value returning function is
a function that will return a value back to the part of the program that called it
Given the Python statement value = ( 42, "universe", "everything) which statement is illegal in Python?
all all illegal
When using the ________ logical operator, both subexpressions must be true for the compound expression to be true.
and
In the split method, if no separator is specified, the default is ____________.
any whitespace character
The ________ method is commonly used to add items to a list.
append
A(n) ________ is any piece of data that is passed into a function when the function is called.
argument
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
A(n) ________ character is a special character that is preceded with a backslash ( \), appearing inside a string literal.
escape
When a function is called by its name during the execution of a program, then it is
executed
When a program needs to save data for later use, it writes the data in a(n) ________.
file
The % symbol is the remainder operator, also known as the ________ operator.
modulus, mod
After the del function or remove method are executed on a list, the items following the eliminated item are ____________.
moved one position left in the list
Lists are ________, which means their elements can be changed in a program.
mutable
What are the values that the variable num contains through the iterations of the following for loop? for num in range(2, 9, 2):
2, 4, 6, 8
In Python the ________ symbol is used as the not equal to operator.
!=
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()
25 because 5 + 2*10
What is the first negative index in a list?
-1
Select all that apply. Which of the following are steps in the program development cycle?
-write the code and correct syntax errors -test the program -correct logic errors -design the program
What are the values that the variable num contains through the iterations of the following for loop? for num in range(4):
0, 1, 2, 3
What is the output of the following print statement? print 'I\'m ready to begin'
I'm ready to begin
What does the following program do? student = 1 while student <= 3: total = 0 for score in range(1, 4): score = int(input("Enter test score: ")) total += score average = total/3 print("Student ", student, "average: ", average) student += 1
It accepts 3 test scores for each of 3 students and outputs the average for *each* student.
Select all that apply. Assume you are writing a program that calculates a user's total order cost that includes sales tax of 6.5%. Which of the following are advantages of using a named constant to represent the sales tax instead of simply entering 0.065 each time the tax is required in the code?
It avoids the risk that any change to the value of sales tax will be made incorrectly or that an instance of the tax value might be missed as might occur if the number had to be changed in multiple locations. It will be easier for another programmer who may need to use this code to understand the purpose of the number wherever it is used in the code. If the tax amount changes to 7.0%, the value will only have to be changed in one place.
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
Both of the following for clauses would generate the same number of loop iterations. for num in range(4): for num in range(1, 5):
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
Different functions can have local variables with the same names.
True
Expressions that are tested by the if statement are called Boolean expressions.
True
In a flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested.
True
In general, tuples are more efficient than lists.
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
Lists are dynamic data structures such that items may be added to them or removed from them.
True
Lists are mutable.
True
One reason not to use global variables is that it makes a program hard to debug.
True
Python allows you to pass multiple arguments to a function.
True
Python function names follow the same rules as those for naming variables.
True
Reducing duplication of code is one of the advantages of using a loop structure.
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 calculate the average of the numeric values in a list, the first step is to get the total of values in the list.
True
Tuples cannot be modified in place.
True
Values used in a Python program that reside in memory are lost when the program terminates.
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
A Boolean variable can reference one of two values which are
True or False
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] *because 10 replaces the value at indice [3], and indexing begins at 0
A set of statements that belong together as a group and contribute to the function definition is known as a
block
What type of loop structure repeats the code based on the value of Boolean expression?
condition controlled loop
What type of loop structure repeats the code a specific number of times?
count controlled loop
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')
Python uses ________ to categorize values in memory.
data types
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
Tuples are ________ sequences which means that once a tuple is created, it cannot be changed.
immutable
Objects that cannot be changed in place are called ____________.
immutable, static, or unchangable
Each element in a tuple has a(n) ________ that specifies its position in the tuple.
index
Which method converts a list of strings into a string value consisting of the elements of the list concatenated together?
join
The built in function ________ returns the length of a sequence.
len
A ____________ is a mutable ordered sequence of Python objects .
list
Which one of the following Python objects can be changed in place?
list
The ________ of a local variable is the function in which that variable is created.
scope
A(n) ________ is an object that holds multiple items of data.
sequence
Which method turns a single string into a list of substrings?
split
A(n) ________ is a name that represents a value stored in the computer's memory.
variable
What does the following expression mean? x <= y
x is less than or equal to y