Chapter 3 Logical Operators Flashcards

1
Q

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:

A

if choice != 10:

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
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

A

True or False

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Expressions that are tested by the if statement are called Boolean expressions.
True or False?

A

True

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
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

A

False

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The not operator is a unary operator which must be used in compound expression.
True or False?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

False

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The following statement will check to see if the turtle’s pen color is ‘green’:
if turtle.pencolor() = ‘green’
True or False?

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In Python, the __ symbol is used as the not-equal-to operator

a. <=
b. !=
c. ==
d. <>

A

!=

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An action is a single alternative decision structure is performed only when the condition is true.
True or False?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

x is less than or equal to y

Chapter 3 Q (page# 112)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Short-circuit evaluation is only performed with the not operator.
True or False?

A

False

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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’

A

and

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Python uses the same symbols for the assignment operator as for the equality operator.
True or False?

A

False

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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

A

control

Chapter 3 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Expressions that are tested by the if statement are called Boolean expressions.
True or False?

A

True

Chapter 3 Q (page# 109)
The if statement is used to create a decision structure, which allows a program to have more than one path of execution. The if statement causes one or more statements to execute only when a Boolean expression is true.