
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to Print Numbers in an Interval
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given the starting and ending range of an interval. We need to print all the numbers in the interval given.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
There are two for loops, first for loop is for getting the numbers in the interval and second loop for the checking whether the number is prime or not.
Now let’s see the implementation.
Example
start = 10 end = 29 for val in range(start, end + 1): # If num is divisible by any number is not prime if val > 1: for n in range(2, val): if (val % n) == 0: break else: print(val)
Output
11 13 17 19 23 29
All variables and functions are declared in the global scope as shown in the figure below.
Conclusion
In this article, we learned about the approach to print numbers in a given interval.
- Related Articles
- Python program to print all Prime numbers in an Interval
- How to Print all Prime Numbers in an Interval using Python?
- Program to count odd numbers in an interval range using Python
- Python program to print even numbers in a list
- Python program to print negative numbers in a list
- Python program to print odd numbers in a list
- Program to find one minimum possible interval to insert into an interval list in Python
- Python program to print an Array
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- How to identify and print all the perfect numbers in some closed interval [ 2, n ] using Python?
- Python Program to Print an Identity Matrix
- Python program to print all Disarium numbers between 1 to 100
- Program to find Prime Numbers Between given Interval in C++
- Python Program to Print an Inverted Star Pattern

Advertisements