73.7k views
5 votes
Write a program that uses a while loop to calculate and print the multiples of 3 from 3 to 21. Your program should print each number on a separate line. Expected Output:

3
6
9
12
15
18
21

User Chul
by
7.1k points

1 Answer

0 votes

Code:

num = 3

while num <= 21:

print(num)

num+=3

Output of code:

3

6

9

12

15

18

21

Step-by-step explanation:

The condition num <= 21 will ensure that the program will only print multiples of 3 up to 21. We set num as 3 since we want to start printing from 3, and we add 3 each time to get the multiples.

Hope this helps :)

User Mr Goobri
by
7.5k points