Completed
Python Loops & Conditions
Questions From This Challenge
Q1output1 mark
What will be the output of the following Python code?
x = 2
for i in range(1, 6):
if i % 2 == 0:
x = x + i
else:
x = x - 1
print(x)
Correct output:
5Q2output1 mark
What will be the output of the following Python code?
count = 0
for ch in "COMPUTER":
if ch in "AEIOU":
count = count + 1
else:
count = count - 1
print(count)
Correct output:
-2Q3mcq1 mark
Which of the following range() expressions generates exactly the values 4, 7, 10, 13?
range(4, 13, 3)
range(4, 14, 3) ✓
range(4, 15, 3)
range(3, 14, 3)
Q4output1 mark
What will be the output of the following Python code?
total = 0
for i in range(2, 12, 2):
if i % 3 == 0:
total = total + i
else:
total = total - 1
print(total)
Correct output:
2Q5mcq1 mark
Which of the following for loops executes exactly 7 times?
for i in range(1, 8):
for i in range(0, 14, 2): ✓
for i in range(2, 15, 2):
for i in range(14, 1, -2):
Q6output1 mark
What will be the output of the following Python code?
result = 1
for i in range(2, 8):
if i % 3 == 0:
result = result + i
else:
result = result - 1
print(result)
Correct output:
6Q7output1 mark
What will be the output of the following Python code?
total = 0
for i in range(2, 9, 2):
if i > 4:
total = total + i
else:
total = total - i
print(total)
Correct output:
12Q8mcq1 mark
Which of the following statements about range(10, 1, -3) is correct?
It generates 10, 7, 4, 1.
It generates 10, 7, 4. ✓
It generates 1, 4, 7, 10.
It generates 10, 8, 6, 4, 2.
Q9output1 mark
What will be the output of the following Python code?
count = 0
for i in range(1, 20):
if i % 4 == 0 or i % 5 == 0:
count = count + 1
print(count)
Correct output:
7Q10mcq1 mark
Which of the following loops prints exactly 12, 9, 6, 3?
for i in range(12, 3, -3):
for i in range(12, 2, -3): ✓
for i in range(12, 1, -3):
for i in range(12, 0, -3):
Q11output1 mark
What will be the output of the following Python code?
total = 0
for num in [5, 8, 11, 14]:
if num % 2 == 0:
total = total + num
else:
total = total - 1
print(total)
Correct output:
20Q12output1 mark
What will be the output of the following Python code?
x = 3
for i in range(2, 7):
if i % 2 == 0:
x = x * 2
else:
x = x + 1
print(x)
Correct output:
30Q13output1 mark
What will be the output of the following Python code?
x = 0
for i in range(3, 10):
if i % 2 == 0:
x = x + i
elif i % 3 == 0:
x = x - i
print(x)
Correct output:
6Q14output1 mark
What will be the output of the following Python code?
x = 5
for i in range(1, 5):
if i % 2 == 0:
x = x + i
else:
x = x * 2
print(x)
Correct output:
24Q15mcq1 mark
Which of the following range() expressions generates exactly five values?
range(2, 12, 2)
range(10, 0, -2)
range(1, 10, 2) ✓
range(5, 15, 3)