Python: Control flow Flashcards
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.
My name is Angelo.
Determine the truth value of the following expression:
(4 <= 2 * 3) and (7 + 1 == 8)
True
Determine the truth value of the following expression:
4 * 5 <= 21 - 1
True
3 ** 2 + 1 != 30 / 3
False
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”
my_cool_variable = 7 + 8 != 13
Determine the truth value of the following expression:
(9 - 4) * 2 == 77 / 7 - 1
True
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”)
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.
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.”)
Is this printed?
This might be printed.