Chapter 3 Logical Operators Flashcards
Which of the following is the correct if clause to determine whether choice is anything other than 10?
a. if not (choice < 10 and choice > 10):
b. if choice != 10:
c. if choice != 10
d. if choice <>10:
if choice != 10:
Chapter 3 Q
A Boolean variable can reference one of two values which are
a. T or F
b. Y or N
c. True or False
d. yes or no
True or False
Chapter 3 Q
Expressions that are tested by the if statement are called Boolean expressions.
True or False?
True
Chapter 3 Q
What is the result of the following Boolean expression, given that
x = 5, y = 3, and z = 8?
x < y or x > x
a. True
b. False
c. 8
d. 5
False
Chapter 3 Q
The not operator is a unary operator which must be used in compound expression.
True or False?
False
Chapter 3 Q (page# 135)
The not operator is a unary operator that takes a Boolean expression as its operand and reverses its logical value. In other words, if the expression is true, the not operator returns false, and if the expression is false, the not operator returns true.
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 < x
a. 5
b. 8
c. True
d. False
False
Chapter 3 Q
The following statement will check to see if the turtle’s pen color is ‘green’:
if turtle.pencolor() = ‘green’
True or False?
False
Chapter 3 Q (page# 142)
When you execute the turtle.pencolor() function without passing it an argument, the function returns the pen;s current drawing color as a sting.
The correct statement should be:
if turtle.pencolor() == ‘green’
- using == (relational operators) for true or false statement not the = (assignment operator)
The decision structure that has two possible paths of execution is known as
a. two alternative
b. double alternative
c. single alternative
d. dual alternative
dual alternative
Chapter 3 Q (page# 118)
Dual alternative decision structure, which has two possible paths of execution - one path is take if a condition is true, and the other pathe is taken if the condition is false.
In Python, the __ symbol is used as the not-equal-to operator
a. <=
b. !=
c. ==
d. <>
!=
Chapter 3 Q
An action is a single alternative decision structure is performed only when the condition is true.
True or False?
True
Chapter 3 Q (page# 110)
Single alternative decision structure provides only one alternative path of execution. if the condition in the diamond symbol is true, we take the alternative path. Otherwise, we exit the structure.
What does the following expression mean?
x <= y
a. x is less than or equal to y
b. x is greater than y
c. x is less than y
d. x is greater than or equal to y
x is less than or equal to y
Chapter 3 Q (page# 112)
Short-circuit evaluation is only performed with the not operator.
True or False?
False
Chapter 3 Q
When using the ___ logical operator, both subexpressions must be true for the compound expression to be true.
a. or
b. and
c. not
d. either ‘OR’ or ‘AND’
and
Chapter 3 Q
Python uses the same symbols for the assignment operator as for the equality operator.
True or False?
False
Chapter 3 Q
A(n) ___ structure is a logical design that controls the order in which a set of statements execute.
a. function
b. control
c. iteration
d. sequence
control
Chapter 3 Q