Python: Control flow Flashcards

1
Q

Which of the following is a Boolean expression?

This quiz is very hard.

My name is Angelo.

Three is the most elegant number.

The New York Yankees are the classiest baseball team.

A

My name is Angelo.

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

Determine the truth value of the following expression:

(4 <= 2 * 3) and (7 + 1 == 8)

A

True

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

Determine the truth value of the following expression:

4 * 5 <= 21 - 1

A

True

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

3 ** 2 + 1 != 30 / 3

A

False

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

Which of the following variables contains a Boolean value?

my_cool_variable = 7 + 8 != 13

my_chill_variable = “This is True.”

my_fun_variable = 2 + 9

my_super_variable = “True” + “False”

A

my_cool_variable = 7 + 8 != 13

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

Determine the truth value of the following expression:

(9 - 4) * 2 == 77 / 7 - 1

A

True

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

Read the following code carefully. What will happen when the code is executed?

x = 0

if x = 0:
print(“x is equal to zero”)
elif x >= 0:
print(“x is greater than zero”)
else:
print(“x is less than zero”)

A

There will be a SyntaxError. The line if x = 0: will cause a SyntaxError because = is not a relational operator. If this was fixed, then x is equal to zero would print.

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

Consider the code below; what would this print to the terminal?

x = 5

if x <= 2:
print(“This is printed”)
if x <= 4:
print(“This is also printed”)
if x <= 6:
print(“Is this printed?”)
if x <= 8:
print(“This might be printed.”)

A

Is this printed?

This might be printed.

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