Python Program to Print Numbers in an Interval
Given a range of numbers, find all the numbers between them.
Input : l = 2, u = 5
Output : 2 3 4 5Input : l = 10, u = 20
Output : 10 11 12 13 14 15 16 17 18 19 20
The idea is to use range function in Python.
# Python program to print all the numbers within an interval l = 10u = 20 for num in range(l, u + 1): print(num) |
chevron_right
filter_none
Output:
10 11 12 13 14 15 16 17 18 19 20
We can also print alternate numbers or numbers with given steps.
# Python program to print all EVEN numbers within an interval l = 10u = 20 for num in range(l, u + 1, 2): print(num) |
chevron_right
filter_none
Output:
10 12 14 16 18 20
Recommended Posts:
- Python program to print all Prime numbers in an Interval
- Python program to print even numbers in a list
- Python program to print all odd numbers in a range
- Python program to print odd numbers in a List
- Python program to print all even numbers in a range
- Python program to print all Strong numbers in given list
- Python program to print all positive numbers in a range
- Python program to print positive numbers in a list
- Python program to print negative numbers in a list
- Python program to print all negative numbers in a range
- Python | Interval Initialization in list
- Program to print first n Fibonacci Numbers | Set 1
- Program to print a pattern of numbers
- Program to print numbers columns wise
- Program to print numbers with diamond pattern
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



