TECHSMART PYTHON UNIT 2; PART 1 TEST
QUESTIONS AND ANSWERS
In the following code, identify the condition that includes the elif-clause.
if x == 1:
print("X is 1")
if y == 2:
print("y is 2")
elif x == w:
print("X is w")
elif x == 5:
print("X is 5")
if x < 53:
print("x is less than 53") - ANSWER if y == 2:
print("y is 2")
elif x == w:
print("X is w")
elif x == 5:
print("X is 5")
Remember that a conditional starts with an if-clause.
Which of the following is not a type of conditional clause?
if, elif, then, or else - ANSWER then
What data type can only be represented as Yes or No and True or False? -
ANSWER boolean
Example of a boolean expression - ANSWER a == b;
The three basic boolean operators are: - ANSWER AND, OR, and NOT.
, How many times will the following code print the statement "Print me"?
x=0
while x < 1000:
print("Print me")
x += 100 - ANSWER 10
Identify the if-clause in the following code.
if x < y:
print("x is smaller")
print("y is bigger") - ANSWER if x < y:
Identify the condition in the following code.
if x < y:
print("x is smaller")
print("y is bigger") - ANSWER x < y
What happens if the condition in a conditional is False? - ANSWER The
program skips the then-block
In the following code, the then-block will never execute. Why?
if 100 < 10:
print("We executed!")
print("Congratulations!")
print("The program finished.") - ANSWER The condition will always be false.
Add a symbol to the conditional so it is formatted correctly.
x = 10
y=5
if x > y
print("x is bigger than y") - ANSWER add a colon after if x > y. Should be
written if x > y:
QUESTIONS AND ANSWERS
In the following code, identify the condition that includes the elif-clause.
if x == 1:
print("X is 1")
if y == 2:
print("y is 2")
elif x == w:
print("X is w")
elif x == 5:
print("X is 5")
if x < 53:
print("x is less than 53") - ANSWER if y == 2:
print("y is 2")
elif x == w:
print("X is w")
elif x == 5:
print("X is 5")
Remember that a conditional starts with an if-clause.
Which of the following is not a type of conditional clause?
if, elif, then, or else - ANSWER then
What data type can only be represented as Yes or No and True or False? -
ANSWER boolean
Example of a boolean expression - ANSWER a == b;
The three basic boolean operators are: - ANSWER AND, OR, and NOT.
, How many times will the following code print the statement "Print me"?
x=0
while x < 1000:
print("Print me")
x += 100 - ANSWER 10
Identify the if-clause in the following code.
if x < y:
print("x is smaller")
print("y is bigger") - ANSWER if x < y:
Identify the condition in the following code.
if x < y:
print("x is smaller")
print("y is bigger") - ANSWER x < y
What happens if the condition in a conditional is False? - ANSWER The
program skips the then-block
In the following code, the then-block will never execute. Why?
if 100 < 10:
print("We executed!")
print("Congratulations!")
print("The program finished.") - ANSWER The condition will always be false.
Add a symbol to the conditional so it is formatted correctly.
x = 10
y=5
if x > y
print("x is bigger than y") - ANSWER add a colon after if x > y. Should be
written if x > y: