Boolean Intro
Applying Boolean
Conditionals
Back to Basics (1)
Back to Basics too!
100
What are the values for Boolean in Python?

a. True, False
b. TRUE, FALSE
c. true, false
d. Yes, No
True and False
100
Which of the following is the correct if clause to determine whether y is in the range 10 through 50?
a. if 10 < y 5
b. if 10 < y or y > 50
c. if 10 > y and y < 50
d. if y > 10 and y < 50
e. if y > 10 or y < 50
d. if y > 10 and y < 50
100
A(n) ____________ statement will execute one block of statements when its condition is true, or another block when its condition is false.
if-else statement
100
Which mathematical operator is used to raise a number to a power (exponent) in Python?
**
100
What value and data type will the variable x be assigned?

x = 11/2
5.5 which is a 'float' (in Python, the / divides full division)
200
How many comparison operators are there in Python?
Six: ==, !=, >, >=, <, <=
200
What is another way to accomplish this comparison?

if x > 10 and x < 20:
if 10 < x < 20:
200
What Python keyword allows us to check for more conditions in case the first condition was false?
The elif keyword (if-elif-else)
200
What character starts a comment in Python?
#
200
What value and data type will the variable y reference?

y = 9//2
4 which is an 'int'

(in Python, the // does integer division and throws away the decimal part)
300
What are the logical operators in Python?
and, or, not
300
What is the result of the following Boolean expression, given, x = 5, y = 3, and z = 8?

x < y or z > x

(True or False?)
True
300
What will this code print?

flag = False
if not flag:
print ('Line 1 will be printed')
else:
print ('Line 2 will be printed')
Line 1 will be printed
300
What data type is the variable "amount" assigned?

amount = 430.87
'float'
300
What is the format (syntax) of the input function?
variable = function (question)

Example:
name = input("What is your name? ")
400
Multiple Boolean expressions can be combined by using a ________ operator to create compound expressions.
logical
400
Which of the following is the correct if clause to use to determine whether X is other than 10?

a. if X != 10:
b. if X != 10
c. if X <> 10:
d. if X <> 10
e. None of the above
a. if X != 10:
400
What will this code print?

x = 10
y = 15

if x%3==0 and y%3==0:
print ('Line 1 will be printed')

elif x%3==0 or y%3==0:
print ('Line 2 will be printed')

else:
print ('Line 3 will be printed')

Line 2 will be printed
400
What data type AND value is the variable "total" assigned?

total = int(98.5)
An int data type. Value is 98.
400
What will this print?

x = "10"
y = "5"
print (x + y)
"105"

(since they are strings, they get merged)
500
When using the _________ operator, one or both sub-expressions must be true for the final expression to be true.
or
500
What is the result of the following Boolean expression, given x = 5, y = 3, and z = 8?

not (x < y or z > x) and y < z

(True or False?)
False
500
What will this code print?

x = 10
y = 15

if x>=y:
print ('Line 1 will be printed')

else:
if x<=y and y!=15:
print ('Line 2 will be printed')

else:
print ('Line 3 will be printed')

Line 3 will be printed
500
If x=10, which print statement will NOT produce a syntax error?

a. print ('I have' x 'pairs of shoes')
b. print('I have,' x ', pairs of shoes)
c. print ('I have', x, 'pairs of shoes')
d. none of the above!
c. print ('I have', x, 'pairs of shoes')

(you need to separate the items with commas!)
500
What will this print?

print( (6-3) * 2 + 7 % 2)
7