Exercise
Factors And Multiples
Objective
Develop a Python program that displays the numbers from 1 to 500 that are multiples of both 3 and 5 on the screen. (Hint: Use the modulo operator to check for divisibility by both 3 and 5.)
Example Python Exercise
Show Python Code
# Use a while loop to display numbers from 1 to 500 that are multiples of both 3 and 5
i = 1
while i <= 500:
if i % 3 == 0 and i % 5 == 0:
print(i)
i += 1
Output
15
30
45
60
75
90
105
120
135
150
165
180
195
210
225
240
255
270
285
300
315
330
345
360
375
390
405
420
435
450
465
480
495
Share this Python Exercise
Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.
In this exercise, you will develop a Python program that prompts the user for a number and a quantity, then displays that number repeated as many...
In this exercise, you will develop a Python program that prompts the user to enter their login and password (both must be integer numbers). The p...
In this exercise, you will develop a Python program that prompts the user for their login and password, both of which must be integers. The progr...
In this exercise, you will develop a Python program that prompts the user for two numbers and displays their division and remainder. If 0 is entered as ...
In this exercise, you will develop a Python program that displays multiplication tables from 2 to 6 using nested "while" loops. The program will iterate throug...
In this exercise, you will develop a Python program that prompts the user to enter a number and a width, and then displays a square of that width using ...