Introduction To Programming Using Python 1st Edition Schneider Test Bank 1
Introduction To Programming Using Python 1st Edition Schneider Test Bank 1
Chapter 3
Multiple Choice (23) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH **.
YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
1. Which function returns the single-character string of the character with ASCII value n for
nonnegative numbers?
a. chr(n) **
b. ascii(n)
c. ord(n)
d. string(n)
2. Given x = 5, y = 7 and z = “kitten” what does the following condition evaluate to?
(x + y) / 2 == len(z)
a. True **
b. False
c. it cannot be determined because integers are being mixes with strings
d. it cases a Traceback error
3. When comparing two lists of different lengths, if all items pairs match up to the end of the
shorter sequence, which sequence is said to be the lesser of the two?
4. Conditions that use the logical operators are called ____________ conditions.
a. compound **
b. logical
c. relational
d. all of the above
5. When Python stops evaluating a compound condition with the logical and operator because a
condition evaluates to False, it is called ____________evaluation.
a. short-circuit **
b. pre-
c. compound
d. first
7. When an if-else statement needs to allow for more than two possible alternatives, you use a(n)
____________ clause.
a. elif **
b. nested
c. fi
d. else
10. When an empty string, list, or tuple is used as a condition, what does it evaluate to?
a. False **
b. True
c. nothing
d. it creates a Traceback error
11. A part of a program that executes a block of code repeatedly is called a(n) ____________.
a. loop **
b. repeater
c. elif
d. circle
12. What Python loop repeatedly executes a block of statements as long as a certain condition is
met?
a. while **
b. for
c. do
d. repeater
13. In a while loop, the line beginning with while is called a(n) ____________.
a. header **
b. intro
c. precursor
d. starter
15. Using a while loop to ensure a proper response is received from a request is called
____________.
a. input validation **
b. verification
c. input identification
d. user validation
16. The ____________ statement causes an exit from anywhere in the body of a loop.
a. break **
17. The ____________ statement causes the current iteration of the body of a loop to terminate
and execution returns to the loop’s header.
a. continue **
b. break
c. pass
d. elif
18. A ____________ is a Boolean-valued variable used to report whether a certain circumstance has
occurred.
a. flag **
b. pass
c. break
d. check
21. When one loop is contained in the body of another loop, it is said to be ____________.
a. nested **
b. entangled
c. surrounded
d. blocked
True/False (20)
Answer: true
Answer: false
Answer: false
4. In order for two tuples to be equal, they must have the same length and corresponding items
must have the same value.
Answer: true
5. isinstance(55.3, int)
Answer: false
6. isinstance(“5”, int)
Answer: false
7. De Morgan’s law can be applied from left to right or from right to left.
Answer: true
Answer: false
Answer: true
10. When indenting a block of statements for an if-else statement, as long as the statements are
indented to the right enough to visually see, the number of spaces for each line does not have to
be exactly the same.
Answer: false
Answer: true
Answer: false
13. Every object in Python has a truth value associated with it.
Answer: true
Answer: true
15. You should never use elif when test conditions are mutually exclusive.
Answer: false
16. The body of a while loop will be continually executed until the continuation condition evaluates
to True.
Answer: false
17. When the break statement is executed, the loop terminates after the body has finished
executing.
Answer: false
Answer: true
Answer: false
Answer: true
Answer: Once it has been determined that a compound condition is true or false regardless of the
remaining conditions, evaluating those conditions uses unnecessary time, and more so if the
condition is complex and time-consuming.
Answer: False
Answer: True
Answer: You cannot use it in an assignment statement because the method does not return a value
to be assigned. It simply reorders the items in the list in place.
Answer:
count = 5
while (count > 0):
Answer:
Woot!
Woot!
Woot!
Woot!
Woot!
Answer: 0, 1, 2, 3, 4, 5
15. Write a for loop that prints “Hello World!” 100 times.
Answer:
for i in range(100):
print(“Hello World!”)