Factors and Multiples - Python Programming Exercise

In this exercise, you will develop a Python program that displays the numbers from 1 to 500 that are multiples of both 3 and 5 on the screen. You will use the modulo operator to check for divisibility by both 3 and 5, which is a key concept in Python programming for performing mathematical operations and handling conditions. By completing this exercise, you will improve your ability to work with loops and conditional statements in Python, allowing you to filter and display values based on specific mathematical criteria. Understanding how to check divisibility using the modulo operator is essential for building efficient Python programs that need to process numbers according to specific rules.

 Category

Mastering Flow Control

 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

 Copy 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

 More Python Programming Exercises of Mastering Flow Control

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.

  •  Repeated Value

    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...

  •  Access Code

    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...

  •  Access Code V2

    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...

  •  Multiple Divisions

    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 ...

  •  Multiple Times Tables (Using While)

    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...

  •  Quadrilateral

    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 ...