Table of 2 with a while loop
Write a Python program to print the table of 2 using a while loop.
2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 2 x 10 = 20
Approach
- Use a counter from 1 to 10.
Solution
i = 1while i <= 10: print(f"2 x {i} = {2 * i}") i += 12 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 2 x 10 = 20
Learn the concept
New to this topic? Read the lesson, then come back.