Gaddis Python 2e Chapter 04
Download file with the answers
Gaddis Python 2e Chapter 04
1 file(s) 110.62 KB
If you are not a member register here to download this file
Chapter Four
MULTIPLE CHOICE
1. A(n) _____ structure is a logical design that controls the order in which a set of statements execute.
a. function
b. control
c. sequence
d. iteration
2. The decision structure that has two possible paths of execution is known as _____.
a. single alternative
b. double alternative
c. dual alternative
d. two alternative
3. Multiple Boolean expressions can be combined by using a logical operator to create _____ expressions.
a. sequential
b. logical
c. compound
d. mathematical
4. When using the _____ operator, one or both subexpressions must be true for the compound expression to be true.
a. Or
b. And
c. Not
d. Maybe
5. Which logical operators perform short-circuit evaluation?
a. or, not
b. not, and
c. or, and
d. and, or, not
6. Which of the following is the correct if clause to determine whether y is in the range 10 through 50?
a. if 10 < y or y > 50
b. if 10 > y and y < 50 c. if y > 10 and y < 50 d. if y > 10 or y < 50
7. A Boolean variable can reference one of two values: _____.
a. yes or no
b. true or false
c. T or F
d. Y or N
8. What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8?
x < y or z > x
a. true
b. false
c. 8
d. 5
9. What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8?
x < y and z > x
a. true
b. false
c. 8
d. 5
10. What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8?
not (x < y or z > x) and y < z
a. true
b. false
c. 8
d. 5
11. What does the following expression mean?
x <= y
a. x is less than y
b. x is less than or equal to y
c. x is greater than y
d. x is greater than or equal to y
12. Which of the following is the correct if clause to use to determine whether choice is other than 10?
a. if choice != 10:
b. if choice != 10
c. if choice <> 10:
d. if choice <> 10
13. When using the _____ operator, both subexpressions must be true for the compound expression to be true.
a. or
b. and
c. not
d. maybe
14. In Python, the _____ symbol is used as the not-equal-to operator.
a. ==
b. <>
c. <= d. != 15. In Python the _____ symbol is used as the equality operator. a. == b. = c. >=
d. <=
TRUE/FALSE
1. True/False: The if statement causes one or more statements to execute only when a Boolean expression is true.
ANS: T
2. True/False: The Python language is not sensitive to block structuring of code.
ANS: F
3. True/False: Python allows you to compare strings, but it is not case sensitive.
ANS: F
4. True/False: Nested decision structures are one way to test more than one condition.
ANS: T
5. True/False: Python uses the same symbols for the assignment operator and the equality operator.
ANS: F
6. True/False: The not operator is a unary operator and it must be a compound expression.
ANS: F
7. True/False: Short-circuit evaluation is performed with the not operator.
ANS: F
8. True/False: Expressions that are tested by the if statement are called Boolean expressions.
ANS: T
9. True/False: Decision structures are also known as selection structures.
ANS: T
10. True/False: An action in a single alternative decision structure is performed only when the condition is true.
ANS: T
FILL IN THE BLANK
1. The _______________ statement is used to create a decision structure.
ANS: if
2. In flowcharting, the _______________ symbol is used to represent a Boolean expression.
ANS: diamond
3. A(n) _______________ decision structure provides only one alternative path of execution.
ANS: single alternative
4. In a decision structure, the action is _______________ executed because it is performed only when a certain condition is true.
ANS: conditionally
5. A(n) _______________ operator determines whether a specific relationship exists between two values.
ANS: relational
6. A(n) _______________ statement will execute one block of statements if its condition is true, or another block if its condition is false.
ANS: if-else
7. Python provides a special version of a decision structure known as the _______________ statement, which makes the logic of the nested decision structure simpler to write.
ANS: if-elif-else
8. The logical _______________ operator reverses the truth of a Boolean expression.
ANS: not
9. Boolean variables are commonly used as _______________ to indicate whether a specific condition exists.
ANS: flags
10. A(n) _______________ expression is made up of two or more Boolean expressions.
ANS: compound
Leave a reply