Assignment instructions
Complete the questions to the best of your ability
Questions for this assignment
What will the following code print?
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 ze...
page2me.hashnode.dev1 min read
Instructor example
What will the following code print?
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 syntax error, because x = 0 is a definition of a variable, not a comparison. In order to be valid, the statement should be if x == 0:
What will be printed?
x = 5
if x <= 2:
print("This is 2")
if x <= 4:
print("This is 4")
if x <= 6:
print("This is 6")
if x <= 8:
print("This is 8")
This is 6
This is 8
The two above statements will be printed, because they are all if statements, so all of them will execute.
What will be printed?
x = 5
if x <= 2:
print("This is 2")
elif x <= 4:
print("This is 4")
elif x <= 6:
print("This is 6")
elif x <= 8:
print("This is 8")
Because these are elif statements, if one's condition is met, only that statement will be printed, and so
This is 6
will be printed.
What is the boolean value of this statement?
(2 <= 2 * 3 / 6) and (7 + 1 == 8)
2 <= 1 is a False statement
8 == 8 is a True statement
False and True is False, because and requires both statements to be True in order for the whole statement to be True.
What is the boolean value of this statement?
(12 > 6 * 3) or ( 7 >= -3 + 4)
12 > 18 is False
7 >= 1 is True
False or True is True, because or only requires one statement to be True for the entire statement to be True.
What is the boolean value of this statement?
not True or False and (not True or not (False and True))
Calculate the parentheses first:
not True or False and (not True or not False)
Then inside the parentheses, not comes first
not True or False and (False or True)
Then calculate the remaining parentheses
not True or False and True
Then calculate not
False or False and True
Then calculate and
False or False
Then calculate or
False
The statement is False.