CIS225 Exam 3
What is unit testing? A. Testing the entire program as one unit. B. Testing separate parts/units of the program separately C. Testing your program by running it repeatedly. D. A way to test the ability of programmers.
Testing separate parts/units of the program separately
Which line would not be found in a truth table for and? a) T T T b) T F T c) F T F d) F F F
T F T
The Boolean operator or returns True when both of its operands are true.
True
The condition x <= y <= z is allowed in Python.
True
The main function is at the top of a functional structure chart.
True
The math.sqrt function cannot compute the square root of a negative number.
True
Top-down design is also called stepwise refinement.
True
Unit-testing is the process of trying out a component of a larger program in isolation.
True
a and (b or c) == (a and b) or (a and c)
True
When a program is being run directly (not imported), the value of __name__ is a) script b) main c) __main__ d) True
__main__
A statement that controls the execution of other statements is called a a) boss structure b) super structure c) control structure d) branch
control structure
What are the advantages of spiral development? A. It makes it easier to tackle a large problem when you don't know ahead of time all the features your program must implement. B. It allows you to add new features and test them even if they weren't part of the initial requirements of the program. C. It allows you to simplify the original problem that may be too complicated to understand initially. D. all of the above E. none of the above
all of the above
Which of the following can be treated as a Boolean expression? a) an int expression b) a float expression c) the result of a comparison operator (such as < or >) d) all of the above
all of the above
Which of the following statements could be true about the following Python code? from random import randrange for i in range(10): print(randrange(10)) A. It might output the numbers 0 through 9 in that older. B. It might output 0 through 9 in some order. C. It might output 0 ten times D. all of the above E. none of the above
all of the above
A Python convention for defining methods that are "private" to a class is to begin the method name with a. "private" b. a pound sign ( # ) c. an underscore ( _ ) d. a hyphen ( - )
an underscore (_)
The best structure for implementing a multi-way decision in Python is a) if b) if-else c) if-elif-else d) try
if-elif-else
A loop pattern that asks the user whether to continue on each iteration is called a(n) a) interactive loop b) end-of-file loop c) sentinel loop d) infinite loop
interactive loop
A multiple choice question is most similar to a) simple decision b) two-way decision c) multi-way decisions d) an exception handler
multi-way decisions
Which of the following is not a valid rule of Boolean algebra? a) (True or x) == True b) (False and x) == False c) not(a and b) == not(a) and not(b) d) (True or False) == True
not(a and b) == not(a) and not(b)
Within a method definition, the instance variable x could be accessed via which expression? a. x b. self.x c. self[ x ] d. self.getX()
self.x
A loop pattern that continues until a special value is input is called a(n) a) interactive loop b) end-of-file loop c) sentinel loop d) infinite loop
sentinel loop
A priming read is part of the pattern for a(n) a) interactive loop b) end-of-file loop c) sentinel loop d) infinite loop
sentinel loop
A graphical view of the dependencies among components of a design is called a A) flow chart B) prototype C) interface D) structure chart
structure chart
A method definition with four formal parameters is generally called with how many actual parameters? a. three b. four c. five d. it depends
three
What is the purpose of an if statement? a) to execute code repeatedly b) to choose whether or not to execute certain code c) to assign a bool value d) all of the above
to choose whether or not to execute certain code
What is the purpose of exception handling? a) to handle errors gracefully so the program does not crash b) to make a program crash c) to make algorithms more efficient d) none of the above
to handle errors gracefully so the program does not crash
A structure in which one decision leads to another set of decisions, which leads to another set of decisions, etc., is called a decision a) network b) web c) tree d) trap
tree
Which of the following statements is true about the Python expression x == 3 or 4? A. it is an invalid statement and the Python interpreter will indicate it is a syntax error. B. It will be true if x is 3 or if x is 4, and false for any other values. C. It will always be false D. It will always be true
It will always be true
Which of the following statements is true about computer simulations? A. They model the real world exactly. B. Once the simulation is written, the input values can be tweaked to see how it affects the results. C. All computer simulations are easy to write. D. All of the above E. none of the above
Once the simulation is written, the input values can be tweaked to see how it affects the results.
A Python string literal can span multiple lines if enclosed with a. " b. ' c. " " " d. \
" " "
What would be the value of total for the following program? total = 0 for i in range(10): for j in range(10): total = total + 1 A. 1 B. 10 C. 20 D. 100
10
Method names should always begin with one or two underscores.
False
Multi-way decisions must be handled by nesting multiple if-else statements.
False
Reading design books alone will make you a great designer.
False
The counted loop pattern uses a indefinite loop.
False
The easiest way to iterate through the lines of a file in Python is to use a while loop.
False
The first parameter of a Python method definition is called this.
False
The python random function returns a pseudo random int.
False
There is usually only one correct solution to a problem involving decision structures.
False
not(a or b) == (not a) or not(b)
False
How is a percent sign indicated in a string formatting template? A) % B) /% C) %% D) /%%
%
Which of the following statements are true? a) An if statement must have an else statement b) An if statement must have an elif statement c) An if statement must have both an elif and an else statement d) An else statement must have a matching if statement
An else statement must have a matching if statement
An expression that evaluates to either true or false is called a) operational b) Boolean c) simple d) compound
Boolean
Which of the following is 'not' a step in pure top-down design? A. Repeat the process on smaller problems B. Detail the algorithm in terms of its interfaces with smaller problems C. Construct a simplified prototype of the system D. Express the algorithm in terms of smaller problems.
Construct a simplified prototype of the system
A Docstring is the same thing as a comment.
False
A developer should use either top-down design or spiral design, but not both.
False
A sentinel loop asks the user whether to continue on each iteration.
False
A simplified version of a program is called a simulation.
False
A two-way decision is implemented using an if-elif statement.
False
An object may have only one instance variable.
False
Computers can generate truly random numbers.
False
Functions that live in objects are called instance variables.
False
In Python conditions, ≠ is written as /=.
False
In data processing, a collection of information about a person or thing is called a file.
False
Which line would not be found in a truth table for or? a) T T T b) T F T c) F T F d) F F F
F T F
Input validation means prompting a user when input is required.
False
A simulation that uses probabilistic events is called A) Monte Carlo B) pseudo random C) Monty Python D) chaotic
Monte Carlo
Which of the following statements is true? a) There is usually only one algorithm to solve a problem b) There is often more than one way to solve a problem and some ways may be more efficient than others c) There is often more than one way to solve a problem but they are all equally efficient d) All of the Above e) None of the Above
There is often more than one way to solve a problem and some ways may be more efficient than others
A Python 'while' implements a indefinite loop.
True
A sentinel loop should not actually process the sentinel value.
True
A simple decision can be implemented with an if statement.
True
A single try statement can catch multiple kinds of errors.
True
A top-down design is best implemented from the top down.
True
A while is a pre-test loop.
True
In a Python class, the constructor is called __init__.
True
In top-down design, the main algorithm is written in terms of functions that don't yet exist.
True
Instance variables go away once a method terminates.
True
It is considered bad style to directly access an instance variable outside of a class definition.
True
New objects are created by invoking a constructor.
True
Strings are compared by lexicographic ordering.
True
In a Button widget, what is the data type of the instance variable active? a) bool b) int c) float d) str
bool
In the racquetball simulation, what data type is returned by the gameOver function? A) bool B) int C) string D) float
bool
What statement can be executed in the body of a loop to cause it to terminate? a) if b) input c) break d) exit
c) break
What Python reserved word starts a class definition? a. def b. class c. object d. __init
class
The term applied to hiding details inside class definitions is a. obscuring b. subclassing c. documentation d. encapsulation
encapsulation
A method definition is similar to a(n) a. loop b. module c. import statement d. function definition
function definition
In top-down design, the subcomponents of the design are A) objects B) loops C) functions D) programs
functions
Which of the following Python statements is invalid? a) if x!=4: b) if x = 4: c) if x ==4: d) if 2 < x < 4:
if x = 4:
In Python, the body of a decision is indicated by a) indentation b) parentheses c) curly braces d) a colon
indentation
A loop that never terminates is called a) busy b) indefinite c) tight d) infinite
infinite
The arrows in a module hierarchy chart depict A) information flow B) control flow C) sticky-note attachments D) one-way streets
information flow
A while loop written as while True A. will always be an infinite loop no matter what the loop body contains B. might be an infinite loop no matter what the loop body contains C. might be an infinite loop depending on what the loop body contains D. will never execute the loop body
might be an infinite loop depending on what the loop body contains
Placing a decision inside of another decision is an example of a) cloning b) spooning c) nesting d) procrastination
nesting
A loop structure that tests the loop condition after executing the loop body is called a a) pre-test loop b) loop and a half c) sentinel loop d) post-test loop
post-test loop
Taking the square root of a negative value with math.sqrt produces a(n) a) ValueError b) imaginary number c) program crash d) stomach ache
program crash
The initial version of a system used in spiral development is called a A) starter kit B) prototype C) mock-up D) beta-version
prototype
Which expression is true approx 66% of the time? A) random () >=66 B) random() <0.66 C) random()<66 D) random()>=0.66
random()>=0.66
Which of the following methods is not part of the Button class in this chapter? a) activate b) deactivate c) setLabel d) clicked
setLabel
Which of the following methods is part of the DieView class in this chapter? a) activate b) setColor c) setValue d) clicked
setValue
The term for an operator that may not evaluate one of its sub-expressions is a) short-circuit b) faulty c) exclusive d) indefinite
short-circuit
The term for an operator that may not evaluate one of its subexpressions is A. short-circuit B. faulty C. exclusive D. indefinite
short-circuit
The easiest place in a system structure to start unit-testing is A) the top B) the bottom C) the middle D) the main function
the bottom