Skip to main content

Program to find number divisible by 3 or 5 in python

To find number divisible by 3 or 5 we have accepted user input. Used for loop and mod operator with If condition.

#Program to find numbers divisible by 3 or 5

rangeNo = int(input("\n\tEnter number upto which you need to find number divisible by 3 or 5\n\t"))

#Loop to print numbers divisible by 3
print('\n\nThese numbers are divisible by 3 upto %d'%rangeNo)
for i in range(1,rangeNo+1) :
    if (i%3 ==0):
        print("\t%d"%i)
        
#Loop to print numbers divisible by 5
print('\n\nThese numbers are divisible by 5 upto %d'%rangeNo)
for i in range(1,rangeNo+1) :
    if (i%5 ==0):
        print("\t%d"%i)

Output

Enter number upto which you need to find number divisible by 3 or 5
	10
	These numbers are divisible by 3 upto 10
	3
	6
	9


These numbers are divisible by 5 upto 10
	5
	10