Exercises: Loops
How to run these
Download
starter.py below, then run
python3 starter.py.
1 Sum 1 to 20
Use a while loop to calculate and print the sum of numbers from 1 to 20 (inclusive).
2 Multiplication table
Use a for loop to print the multiplication table of 7, from 7 x 1 up to 7 x 10.
3 Reverse a number
Given n = 1234, reverse its digits using % and // in a while loop (result should be 4321).
🐞 Task 4 — Debug the Code
This is supposed to print 1 through 10 inclusive, but it stops at 9. Find and fix the bug.
for i in range(1, 10):
print(i)