1.)Which of the following is a Boolean expression? Select all that apply
a) True
b) 3 == 4
c) 3 + 4
d) 3 + 4 == 7
e) "False"
2.)What is the correct Python expression for checking to see if a
number stored in a variable x is between 0 and 5.
a) x > 0 and < 5
b) 0 < x < 5
c) x > 0 or x < 5
d) x > 0 and x < 5
3.)Which of the following properly expresses the precedence of
operators(using parentheses) in the following expression: 5 * 3 > 10 and 4
+ 6 ==11
a) ((5*3) > 10) and ((4+6) == 11)
b) (5*(3 > 10)) and (4 + (6 == 11))
c) ((((5*3) > 10) and 4)+6) == 11
d) ((5*3) > (10 and (4+6))) == 11
4.) How many statements can appear in each block (the if and the else)
in a conditional statement?
a) Just one
b) Zero or more.
c) One or more.
d) One or more, and each must contain the same number.
5.) What does the following code print (choose from output a, b, c or
nothing).
if (4 + 5 == 10):
print("TRUE")
else:
print("FALSE")
a.
TRUE
b.
FALSE
c.
TRUE
FALSE
a) Output a
b) Output b
c) Output c
d) Nothing will be printed
6.) What does the following code print?
if (4 + 5 == 10):
print("TRUE")
else:
print("FALSE")
print("TRUE")
a.
TRUE
b.
TRUE
FALSE
c.
FALSE
TRUE
d.
TRUE
FALSE
TRUE
a) Output a
b) Output b
c) Output c
d) Output d
7.) What does the following code print?
x = -10
if x < 0:
print("The negative number ", x, " is not valid here.")
print("This is always printed")
a.
This is always printed
b.
The negative number -10 is not valid here
This is always printed
c.
The negative number -10 is not valid here
a) Just one
b) Zero or more.
c) One or more.
d) It will cause an error because every if must have an else clause.
8.) Will the following code cause an error?
x = -10
if x < 0:
print("The negative number ", x, " is not valid here.")
else:
print(x, " is a positive number")
else:
print("This is always printed")
a) No
b) Yes
9.) Will the following code cause an error?
x = -10
if x < 0:
print("The negative number ", x, " is not valid here.")
else:
if x > 0:
print(x, " is a positive number")
else:
print(x," is 0")
a) No
b) Yes
10). Which of I, II, and III below gives the same result as the following nested if?
# nested if-else statement
x = -10
if x < 0:
print("The negative number ", x, " is not valid here.")
else:
if x > 0:
print(x, " is a positive number")
else:
print(x, " is 0")
I.
if x < 0:
print("The negative number ", x, " is not valid here.")
else (x > 0):
print(x, " is a positive number")
else:
print(x, " is 0")
II.
if x < 0:
print("The negative number ", x, " is not valid here.")
elif (x > 0):
print(x, " is a positive number")
else:
print(x, " is 0")
III.
if x < 0:
print("The negative number ", x, " is not valid here.")
if (x > 0):
print(x, " is a positive number")
else:
print(x, " is 0")
a) I only
b) II only
c) III only
d) II and III
e) I, II, and III
11.) What will the following code print if x = 3, y = 5, and z = 2?
if x < y and x < z:
print ("a")
elif y < x and y < z
print ("b")
else:
print ("c")
a) a
b) b
c) c
12.) What is a Boolean function?
a) A function that returns True or False
b) A function that takes True or False as an argument
c) The same as a Boolean expression
13.) Is the following statement legal in Python (assuming x, y and z are defined to be numbers)?
return x + y < z
a) Yes
b) No