IS340 Midterm 1
What is the value of x after the following code segment? x = len("Hello World!")
12
What are the two parts of an if statement?
A condition and a body
A loop inside another loop is called:
A nested loop
Which of the following statements is correct about a sentinel?
A sentinel is a value that indicates the end of an input sequence.
When testing code for correctness, it always makes sense to
Aim for complete coverage of all decision points
High-level programming languages were created to:
Allow programmers to specify the program actions at a high level
What is the difference between an editor and an interpreter?
An editor allows program files to be written and stored; an interpreter translates and executes program files
An integrated development environment (IDE) bundles tools for programming into a unified application. What kinds of tools are usually included?
An editor and a interpreter
Given the following list of strings, what is the correct order using lexicographic ordering: "Ann", "amy", "Heather", "hanna", "joe", "john", "Leo", "Jim" ?
Ann, Heather, Jim, Leo, amy, hanna, joe, john
When hand-tracing a portion of code, which statement about Boolean conditions is true?
They are crucial to evaluate since they determine if-statement conditions and looping.
What is output by the following psuedocode segment? values contains the list items "Q", "W", "E", "R", "T", "Y" print(values[2 : 4])
["E", "R"]
Given the following psuedocode, what are the contents of the list fullNames? firstNames contains list items "Joe", "Jim", "Betsy", "Shelly" lastNames contains list items "Jones", "Patel", "Hicks", "Fisher" fullNames = firstNames + lastNames
["Joe", "Jim", "Betsy", "Shelly", "Jones", "Patel", "Hicks", "Fisher"]
What is the resulting contents of the list values after this psuedocode snippet? values contains the list items 1991, 1875, 1980, 1965, 2000 values.sort()
[1875, 1965, 1980, 1991, 2000]
What is a list in Python?
a container that stores a collection of elements that are arranged in a linear or sequential order
What is printed from the following code snippet: message = "ho.." print(message * 3)
ho..ho..ho..
Which of the following expressions represents a legal way of checking whether a value assigned to the num variable is either less than 100 or more than 200 (exclusive)?
if num < 100 or num > 200
Using De Morgan's law, what is the equivelant to this statement? if not (state == "PA" or state == "OH")
if state != "PA" and state != "OH"
Is the following code snippet legal?
b = False while b != b : print("Do you think in Python?")
Which statement correctly tests if the user entered the letter Y?
if userInput == "Y" :
What is the difference between a list and a string?
lists can hold values of any type, whereas strings are only sequences of characters
A ___________________________ is a sequence of instructions with a name.
function
What is the resulting content of the list after this code snippet? min(["Roland", "Kent", "Ravi", "Amy"])
"Amy"
What symbol is used to indicate a comment in Python?
#
What extension is used for Python files?
.py
What is the index value of the letter 'h' in the string below ? message = "hello"
0
What is the sentinel value in the following code segment value = 15 x = int(input("Enter an integer: ")) while x != 0 : value = value * 2 print(value + 3) x = int(input("Enter an integer: "))
0
What is the value of result after the following code snippet? num1 = 10 num2 = 20 num3 = 2 result = num1 // num2 // num3 print(result)
0
How many times will the following loop run? i = 0 while i < 10 : print(i) i = i + 1
10
How many copies of the letter A are printed by the following loop? i = 1 while i < 5 : print("A") i = i + 1
4
Given the following list, what value is at index 5? values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
6
What Python statement exits the function and gives the result to the caller?
return
What part of the computer carries out arithmetic operations, such as addition, subtract, multiplication and division?
CPU
Which of the following is true about functions in Python?
Functions can have multiple arguments and can return one return value.
The process of hand-tracing code is valuable because
It gives valuable insight that you do not get by running the code.
Parameter variables should not be changed within the body of a function because
It is confusing because it mixes the concept of a parameter with that of a variable
When a program begins to run,
It is moved to the CPU's memory
Which of the following variable names follows the Python naming convention for constants?
MAXSIZE
What is wrong with the following code? def grade(score) : if score >= 90 : return "A" elif score >= 80 : return "B" elif score >= 70 : return "C" elif score >= 60 : return "D"
No return statement for all logic paths
Which of the following is NOT a good practice when developing a computer program?
Put as many statements as possible into the main function
What is wrong with the following code snippet: num1 = 10 num2 = 20 num3 = 30total = Num1 + Num2 + Num3
Python is case sensitive so Num1, Num2, and Num3 are undefined
Which error type does the "off-by-one" error belong to?
Run-time error
What is wrong with the following function for computing the amount of tax due on a purchase? def taxDue(amount, taxRate) : amount = amount * taxRate def main() : . . . total = taxDue(subtotal, TAX_RATE) . . .
The function must return a value
How is a value stored in a variable?
an assignment statement
Which operators listed below are considered boolean operators:
and / or
What is supplied to a function when it is called?
arguments
What is the valid range of index values for a list?
at least zero and less than the number of elements in the list
The Python compiler reads the file containing your source code and converts it to:
byte code
What is the opposite of this condition: count > 10?
count <= 10
Computers are machines that:
execute programs.
Given the definition of a list: names = [] which statement correctly adds "Harry" to the list?
names.append("Harry")
Suppose that b is False and x is 0. Which of the following expressions evaluates to True?
not b or x == 1
Which of the following statements correctly multiplies num1 times num2?
num1 * num2
Which of the following conditions is true, given that num1 contains 3 and num2 contains 4?
num1 - num2 <= 0
Given the following code snippet, what is considered a parameter variable(s)? def mystery(num1, num2) : result = num1 ** num2 return result mystery(10, 2)
num1, num2
What is the right way to assign the value of num + 10 to num2?
num2 = num + 10
The Central Processing Unit is primarily responsible for:
performing program control and data processing.
What is a sequence of characters?
string
What is wrong with the following code snippet? mystery(10, 2) def mystery(num1, num2) : result = num1 ** num2 return result
the function must be defined before the statement that calls it
For the list: prices = [10.00, 15.50, 13.25, 20.15], what value is contained in prices?
the location of the list
The following while loop should continue to run as long as the user does not enter a negative number. What condition should be used to achieve this behavior? x = int(input("Enter an integer: ")) while ____________ : x = int(input("Enter an integer: "))
x >= 0