
- 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
How to Print all Prime Numbers in an Interval using Python?
Prime number is defined as a number not divisible by any other number except 1 and itself. Hence to ascertain that a number is prime, it should be checked for divisibility by all numbers between 1 and itself excluding both.
Following program lists all prime numbers between 1 to 100. Outer loop generates numbers in this range. Inner loop goes from 2 to each number in outer loop and successively checks divisibility by % operator. If it is not divisible by all numbers in inner range, it prints out that number
for i in range(101): for j in range(2,i-1): if i%j==0: break else: print (i)
- Related Articles
- Python program to print all Prime numbers in an Interval
- Python Program to Print Numbers in an Interval
- How to identify and print all the perfect numbers in some closed interval [ 2, n ] using Python?
- How to generate prime numbers using Python?
- Program to count odd numbers in an interval range using Python
- Print prime numbers with prime sum of digits in an array
- Print all prime numbers less than or equal to N in C++
- Print all Semi-Prime Numbers less than or equal to N in C++
- How to Find Armstrong Number in an Interval using Python?
- Program to find Prime Numbers Between given Interval in C++
- Print prime numbers in a given range using C++ STL
- Program to print prime numbers in a given range using C++ STL
- Sum of all prime numbers in an array - JavaScript
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range

Advertisements