Completed
Conditional Statements
Questions From This Challenge
Q1mcq1 mark
What is the output of the following code?
n = 7
if n % 2 == 0:
print("Even")
else:
print("Odd")
Even
Odd ✓
0
Error
Q2mcq1 mark
What is the output of the following code?
marks = 55
if marks >= 90:
print("A")
elif marks >= 75:
print("B")
elif marks >= 50:
print("C")
else:
print("D")
A
B
C ✓
D
Q3mcq1 mark
What is the output of the following code?
a = 8
b = 12
if a > 5:
if b > 10:
print("Both")
else:
print("OnlyA")
else:
print("Neither")
Both ✓
OnlyA
Neither
Error
Q4mcq1 mark
What is the output of the following code?
p = 4
q = 9
if p > 0 and q < 0:
print("X")
elif p > 0 or q < 0:
print("Y")
else:
print("Z")
X
Y ✓
Z
Error
Q5mcq1 mark
Which of these correctly describes the behaviour of an if-elif-else chain in Python?
As soon as one condition evaluates to True, its block runs and the rest of the chain is skipped ✓
Every condition in the chain is checked and every True block is executed
The elif blocks run first, then the if block is checked
The else block always executes in addition to any True elif block
Q6mcq1 mark
What is the output of the following code?
temp = 30
if temp > 35:
print("Hot")
else:
if temp > 25:
print("Warm")
else:
print("Cool")
Hot
Warm ✓
Cool
Error
Q7output1 mark
What is the output?
x = 12
if x > 10:
print("Big")
else:
print("Small")
Correct output:
BigQ8output1 mark
What is the output?
score = 75
if score >= 90:
print("Grade A")
elif score >= 75:
print("Grade B")
elif score >= 60:
print("Grade C")
else:
print("Grade D")
Correct output:
Grade BQ9output1 mark
What is the output?
a = 6
b = 3
if a > 5:
if a % b == 0:
print("Divisible")
else:
print("NotDivisible")
else:
print("Small")
Correct output:
DivisibleQ10output1 mark
What is the output?
x = 5
if x > 0:
print("Positive")
if x > 3:
print("GreaterThan3")
if x > 10:
print("GreaterThan10")
Correct output:
Positive
GreaterThan3Q11output1 mark
What is the output?
m = 14
n = 21
if m % 2 == 0 and n % 2 == 0:
print("BothEven")
elif m % 2 == 0 or n % 2 == 0:
print("OneEven")
else:
print("NoneEven")
Correct output:
OneEvenQ12output1 mark
What is the output?
num = -4
if num > 0:
if num % 2 == 0:
print("PositiveEven")
else:
print("PositiveOdd")
elif num < 0:
if num % 2 == 0:
print("NegativeEven")
else:
print("NegativeOdd")
else:
print("Zero")
Correct output:
NegativeEvenQ13output1 mark
What is the output?
a = 10
b = 20
c = 15
avg = (a + b + c) / 3
if avg > 15:
print("High")
else:
print("Low")
Correct output:
LowQ14output1 mark
What is the output?
grade = "B"
if grade == "A":
print("Excellent")
elif grade == "B":
if 1 == 1:
print("Good")
else:
print("Unknown")
else:
print("Needs Improvement")
Correct output:
GoodQ15output1 mark
What is the output?
s = "25"
n = int(s)
if n > 20:
print("Above20")
else:
print("Below20")
Correct output:
Above20