- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print all the numbers divisible by 3 and 5 for a given number
This is a python program to print all the numbers which are divisible by 3 and 5 from a given interger N. There are numerous ways we can write this program except that we need to check if the number is fully divisble by both 3 and 5.
Below is my code to write a python program to print all the numbers divisible by 3 and 5 −
lower = int(input("Enter lower range limit:")) upper = int(input("Enter upper range limit:")) for i in range(lower, upper+1): if((i%3==0) & (i%5==0)): print(i)
Enter lower range limit:0 Enter upper range limit:99 0 15 30 45 60 75 90
Above we try to print all the numbers between 0 and 99 which are divisble by 3 and 5. Same program can be used to print all the number between 0 and 1000 which are divisible by 3 and 5, we just need to alter our range and our output will be something like,
Enter lower range limit:0 Enter upper range limit:1000 0 15 30 45 60 75 90 105 120 135 150 165 180 195 .... .... 915 930 945 960 975 990
In case we want to write a program which will print all the numbers in a range divisible by a given number not the fixed number like above, i just need to update by program like,
#Incase we want to print all number between a range divided by any given number n = int(input("Enter the number to be divided by:")) for i in range(lower, upper+1): if(i%n==0): print(i)
Below the steps to write above code −
Take the lower and upper limit .i.e. the range from the user.
Take the number to be divided by from the user. In case of our main problem, because we know that numbers(3 and 5), i write the 3 and 5 in the if statement only.
Using a loop with &(and) operator statement(so that it print only those numbers which are divisble by both 3 & 5), prints all the factors which is divisible by the number.
- C# program to print all the numbers divisible by 3 and 5 for a given number
- Program to print all the numbers divisible by 3 and 5 in C++
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- Golang Program to Find the Numbers which are Divisible by 7 and Multiple of 5 in a Given Range
- Largest number with the given set of N digits that is divisible by 2, 3 and 5 in C++
- Python Program for Efficient program to print all prime factors of a given number
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Python Program to Print all Integers that are not Divisible by Either 2 or 3 and Lie between 1 and 50
- Divide number into two parts divisible by given numbers in C++ Program
- Binary Prefix Divisible By 5 in Python
- Count n digit numbers divisible by given number in C++
- Golang Program to print all integers between a range that aren't divisible by either 2 or 3
- Python Program for Smallest K digit number divisible by X
- C Program for efficiently print all prime factors of a given number?