Quiz Details
QZ-20260504-40215
Topics:
Loops for python
If else statements for python
Difficulty:
Level 5 - Very Hard
Questions:
13
Language:
English (English)
Generated:
May 04, 2026 at 10:39 AM
Generated by:
Patience Juliet
Instructions: Select an answer for each question and click "Check Answer" to see if you're correct. Then view the explanation to learn more!
1 What will be the output of the following code: 'for i in range(3): print(i * 2)'?
Correct Answer:
D
Explanation: The loop iterates over 0, 1, and 2, multiplying each by 2, thus producing the output 0, 2, and 4.
Explanation: The loop iterates over 0, 1, and 2, multiplying each by 2, thus producing the output 0, 2, and 4.
2 What will the following code print: 'x = 10; if x > 5: print("Greater"); else: print("Lesser")'?
Correct Answer:
C
Explanation: Since x is greater than 5, the if condition is true, and 'Greater' is printed.
Explanation: Since x is greater than 5, the if condition is true, and 'Greater' is printed.
3 What does the following code snippet do: 'for i in range(5): if i == 3: break; print(i)'?
Correct Answer:
B
Explanation: The loop prints numbers from 0 to 2, and breaks when i equals 3.
Explanation: The loop prints numbers from 0 to 2, and breaks when i equals 3.
4 In the following code, what will be printed: 'x = 7; if x < 5: print("Low"); elif x < 10: print("Medium"); else: print("High")'?
Correct Answer:
B
Explanation: x is 7, which is less than 10 but greater than 5, so 'Medium' is printed.
Explanation: x is 7, which is less than 10 but greater than 5, so 'Medium' is printed.
5 What is the output of this code: 'for i in range(3, 6): print(i)'?
Correct Answer:
C
Explanation: The range starts at 3 and goes up to (but does not include) 6, printing 3, 4, and 5.
Explanation: The range starts at 3 and goes up to (but does not include) 6, printing 3, 4, and 5.
6 What will the following code display: 'x = -1; if x >= 0: print("Positive"); else: print("Negative")'?
Correct Answer:
B
Explanation: Since x is -1, the condition x >= 0 is false, so 'Negative' is printed.
Explanation: Since x is -1, the condition x >= 0 is false, so 'Negative' is printed.
7 What will the output be for this code: 'for i in range(2): for j in range(2): print(i, j)'?
Correct Answer:
B
Explanation: This nested loop prints all combinations of i and j for i in [0,1] and j in [0,1].
Explanation: This nested loop prints all combinations of i and j for i in [0,1] and j in [0,1].
8 What is the outcome of the following code: 'x = 20; if x % 2 == 0: print("Even"); elif x % 2 != 0: print("Odd"); else: print("Error")'?
Correct Answer:
B
Explanation: Since 20 is divisible by 2, the first condition is true, and 'Even' is printed.
Explanation: Since 20 is divisible by 2, the first condition is true, and 'Even' is printed.
9 What will be the output of 'for i in range(1, 10, 3): print(i)'?
Correct Answer:
A
Explanation: This loop starts at 1, goes to 10, and increments by 3 each time, resulting in 1, 4, and 7.
Explanation: This loop starts at 1, goes to 10, and increments by 3 each time, resulting in 1, 4, and 7.
10 What will happen if 'x = 0; if x: print("True"); else: print("False")' is executed?
Correct Answer:
D
Explanation: In Python, 0 is considered falsy, so the else block executes, printing 'False'.
Explanation: In Python, 0 is considered falsy, so the else block executes, printing 'False'.
11 What is the output of the following code: 'for i in range(-1, -5, -1): print(i)'?
Correct Answer:
C
Explanation: The range function generates numbers from -1 to -4, resulting in -1, -2, -3, and -4.
Explanation: The range function generates numbers from -1 to -4, resulting in -1, -2, -3, and -4.
12 What will be printed by this code: 'x = 5; if x < 3: print("Too Low"); elif x > 7: print("Too High"); else: print("Just Right")'?
Correct Answer:
D
Explanation: x is 5, which does not satisfy the first two conditions, so 'Just Right' is printed.
Explanation: x is 5, which does not satisfy the first two conditions, so 'Just Right' is printed.
13 What will the following code output: 'for i in range(4): print("#" * i)'?
Correct Answer:
A
Explanation: The loop prints a number of '#' characters corresponding to the value of i, resulting in 0, 1, 2, and 3 '#' characters.
Explanation: The loop prints a number of '#' characters corresponding to the value of i, resulting in 0, 1, 2, and 3 '#' characters.