Challenge - 5 Problems
Range Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of range() with step
What is the output of this Python code?
result = []
for i in range(2, 10, 3):
result.append(i)
print(result)Python
result = [] for i in range(2, 10, 3): result.append(i) print(result)
Attempts:
2 left
💡 Hint
Remember that range(start, stop, step) includes start but excludes stop.
✗ Incorrect
range(2, 10, 3) starts at 2 and adds 3 each time until it reaches or passes 10. So it produces 2, 5, 8.
❓ Predict Output
intermediate2:00remaining
Counting iterations with negative step
What will be printed by this code?
count = 0
for x in range(10, 0, -2):
count += 1
print(count)Python
count = 0 for x in range(10, 0, -2): count += 1 print(count)
Attempts:
2 left
💡 Hint
Count how many numbers are generated from 10 down to 1 stepping by -2.
✗ Incorrect
range(10, 0, -2) generates 10, 8, 6, 4, 2. That's 5 numbers, so count is 5.
🧠 Conceptual
advanced1:30remaining
Behavior of range() with equal start and stop
What does
list(range(5, 5)) produce in Python?Attempts:
2 left
💡 Hint
Think about whether the stop value is included or excluded.
✗ Incorrect
range(start, stop) includes start but excludes stop. If start == stop, no numbers are generated.
❓ Predict Output
advanced2:30remaining
Output of nested loops with range()
What is the output of this code?
result = []
for i in range(1, 4):
for j in range(i):
result.append(j)
print(result)Python
result = [] for i in range(1, 4): for j in range(i): result.append(j) print(result)
Attempts:
2 left
💡 Hint
Look at how many times the inner loop runs for each outer loop iteration.
✗ Incorrect
For i=1, j runs 0; for i=2, j runs 0,1; for i=3, j runs 0,1,2. All appended in order.
🔧 Debug
expert1:30remaining
Identify the error in this range usage
What error does this code raise?
for i in range(5, 1, 1):
print(i)Python
for i in range(5, 1, 1): print(i)
Attempts:
2 left
💡 Hint
Check if the step direction matches the start and stop values.
✗ Incorrect
range(5, 1, 1) tries to count up from 5 to 1 but 1 is less than 5, so no values are generated.