0
0
Pythonprogramming~20 mins

Counter-based while loop in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
While Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple counter-based while loop
What is the output of this Python code?
Python
count = 0
while count < 3:
    print(count)
    count += 1
A
1
2
B
1
2
3
C
0
1
2
3
D
0
1
2
Attempts:
2 left
💡 Hint
Remember, the loop runs while count is less than 3, starting from 0.
Predict Output
intermediate
2:00remaining
Value of counter after loop ends
What is the value of variable 'counter' after this code runs?
Python
counter = 5
while counter > 0:
    counter -= 2
A0
B-1
C1
D2
Attempts:
2 left
💡 Hint
Check how counter changes each loop iteration until the condition fails.
🔧 Debug
advanced
2:00remaining
Identify the error in this counter-based while loop
What error does this code produce when run?
Python
i = 0
while i < 5:
    print(i)
    i += 1
ASyntaxError
BTypeError
CIndentationError
DNameError
Attempts:
2 left
💡 Hint
Check the syntax of the while statement line.
Predict Output
advanced
2:00remaining
Output of a while loop with break and counter
What is the output of this code?
Python
count = 0
while True:
    if count == 3:
        break
    print(count)
    count += 1
A
1
2
3
B
0
1
2
3
C
0
1
2
D
0
1
2
3
4
Attempts:
2 left
💡 Hint
The loop breaks when count reaches 3, so it does not print 3.
Predict Output
expert
3:00remaining
Final value of counter with complex condition
What is the final value of 'counter' after this code runs?
Python
counter = 10
while counter > 0:
    counter -= 3
    if counter == 4:
        counter += 1
A-1
B1
C0
D4
Attempts:
2 left
💡 Hint
Track the counter value each loop iteration carefully.