Booleans Practice Quiz¶
CS20-FP2 Investigate how control structures affect program flow.
To confirm that you understand the major concepts you’ve seen in Python, try to answer the following questions without opening Python.
Question 1¶
- True
- Great!
- False
- The expression a == 6 evaluates to True because a is indeed 6.
boolean-quiz1: What would the following print?:
a = 6
b = 10
print(a == 6)
Question 2¶
- True
- Great!
- False
- The expression b == 6 evaluates to False, so not (b == 6) evaluates to True.
boolean-quiz2: What would the following print?:
a = 6
b = 10
print( not (b == 6) )
Question 3¶
- True
- Great!
- False
- The expression a == 10 evaluates to False, but b == 10 evaluates to True, so the overall expression evaluates to True.
boolean-quiz3: What would the following print?:
a = 6
b = 10
print( a == 10 or b == 10 )
Question 4¶
- True
- Great!
- False
- The expression a == 6 and 10 evaluates to True because the if statement does not have a full condition on both sides of the and operator. In other words, the a == 6 evaluates to True and the 10 evaluates to True. This is a common error when writing a boolean question. What is likely intended is a == 6 and a === 10.
boolean-quiz4: What would the following print?:
a = 6
b = 10
if a == 6 and 10:
print("True")
else:
print("False")
Question 5¶
- True
- Great!
- False
- The expression a == 10 evaluates to False, so not a == 10 evaluates to True, and b == 10 is True, so the overall expression is True.
boolean-quiz5: What would the following print?:
a = 6
b = 10
print( not a == 10 and b == 10 )
Question 6¶
- True
- The expression a == 10 evaluates to False, and not b == 10 evaluates to False, so the overall expression is False.
- False
- Great!
boolean-quiz6: What would the following print?:
a = 6
b = 10
print( a == 10 or not b == 10 )
Question 7¶
- True
- Great!
- False
- The expression a == 6 evaluates to True and not a == 10 evaluates to True, so the overall expression is True.
boolean-quiz7: What would the following print?:
a = 6
b = 10
print( a == 6 and (not a == 10) )
Question 8¶
- True
- The expression not a == 10 evaluates to True and not b == 10 evaluates to False, so the overall expression inside the parentheses is True, and the outer not makes it False.
- False
- Great!
boolean-quiz8: What would the following print?:
a = 6
b = 10
print( not ( not a == 10 or not b == 10) )
Question 9¶
- True
- The expression a != 6 evaluates to False, so the overall expression is False.
- False
- Great!
boolean-quiz9: What would the following print?:
a = 6
b = 10
print( a != 6 and b == 10 )
Question 10¶
- True
- Great!
- False
- The expression a != 10 evaluates to True and b != 10 evaluates to False, so the overall expression inside the parentheses is False, and the outer not makes it True. The second part of the expression not b == 5 evaluates to True, so the overall expression is True.
boolean-quiz10: What would the following print?:
a = 6
b = 10
print( not ( a != 10 or b != 10) or not b == 5)