Python Program to Print Numbers Divisible by 3, 5 and 7

Python program to print numbers divisible by 3, 5 and 7; Through this tutorial, i will write a program in python to print which are divisible by 3, 5 and 7 using for and while loop.

Python Program to Print Numbers Divisible by 3, 5 and 7

See the following python program to check if a number is divisible by 3, 5 and 7; as shown below:

  • Python program to print numbers divisible by 3 and 5 using for loop
  • Python program to print numbers divisible by 7 using for loop
  • Python program to print first n numbers divisible by 5 using while loop

Python program to print numbers divisible by 3 and 5 using for loop

start = int(input("Enter start number:"))
end = int(input("Enter last number:"))
for i in range(start, end+1):
   if((i%3==0) & (i%5==0)):
      print(i)

Output

Enter start number: 1
Enter last number: 30
15
30

Python program to print numbers divisible by 7 using for loop

# Python program to print numbers divisible by 7 using for loop
start = int(input("Enter start number:"))
end = int(input("Enter last number:"))
for i in range(start, end+1):
   if(i%7==0):
      print(i)

Output

Enter start number: 1
Enter last number: 50
7
14
21
28
35
42
49

Python program to print first n numbers divisible by 5 using while loop

# Python program to print numbers divisible by 7 using while loop
start = int(input("Enter start number:"))
end = int(input("Enter last number:"))
while(start<=end):
    if(start%5==0):
      print(start)
    start += 1

Output

Enter start number: 1
Enter last number: 50
5
10
15
20
25
30
35
40
45
50

Recommended Python Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.