0% found this document useful (0 votes)
10 views

Python Program to Print All Prime Numbers in an Interval

The document provides a Python tutorial focused on printing all prime numbers within a specified interval using for loops. It includes example code and explanations about prime numbers, along with related Python programming topics. Additionally, it offers links to other Python examples and tutorials.

Uploaded by

chidziwosteven
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Program to Print All Prime Numbers in an Interval

The document provides a Python tutorial focused on printing all prime numbers within a specified interval using for loops. It includes example code and explanations about prime numbers, along with related Python programming topics. Additionally, it offers links to other Python examples and tutorials.

Uploaded by

chidziwosteven
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

JAVA | C TUTORIAL | C++ | KOTLIN | SWIFT | R TUTORIAL

TUTORIALS EXAMPLES BUILT-IN FUNCTIONS GET APP 

PYTHON EXAMPLES
Python Program to Print all Prime Numbers in an
Interval
Check if a Number is Positive, Negative
or 0 In this program, you'll learn to print all prime numbers within an interval using for loops
and display it.

Check if a Number is Odd or Even

Check Leap Year

Find the Largest Among Three Numbers

To understand this example, you should have the knowledge of following Python
Check Prime Number programming topics:

Print all Prime Numbers in an Interval Python if...else Statement


Python for Loop
Find the Factorial of a Number Python break and continue

A positive integer greater than 1 which has no other factors except 1 and the number itself
is called a prime number.

2, 3, 5, 7 etc. are prime numbers as they do not have any other factors. But 6 is not prime
(it is composite) since, 2 x 3 = 6 .

Source Code
script.py IPython Shell
1 # Python program to display all the prime numbers within an interval
2
3 # change the values of lower and upper for a different result
4 lower = 900
5 upper = 1000
6
7 # uncomment the following lines to take input from the user
8 #lower = int(input("Enter lower range: "))
Receive the latest tutorial 9 #upper = int(input("Enter upper range: "))
to improve your 10
11 print("Prime numbers between",lower,"and",upper,"are:")
programming skills.
12
13 for num in range(lower,upper + 1):
14 # prime numbers are greater than 1
Enter Email Address* Join 15 if num > 1:
16 for i in range(2,num):
17 if (num % i) == 0:
18 break
19 else:
20 print(num)

Run 

Powered by DataCamp

Get Templates
(Free)
Find Templates,
Download Now
RECOMMENDED READINGS FreeTemplateFinder

Python Program to Check Prime


Number Output

Python Program to Find Armstrong


Prime numbers between 900 and 1000 are:
Number in an Interval
907
Python Program to Find Numbers 911
Divisible by Another Number 919
929
Python Program to Find the Sum of
937
Natural Numbers
941
Python Program to Find the Largest 947
Among Three Numbers 953
967
971
977
983
991
997

Here, we store the interval as lower for lower interval and upper for upper interval, and nd
prime numbers in that range. Visit this page to understand the code to check for prime
numbers.

Check out these related Python examples:

Find Armstrong Number in an Interval


Check Prime Number
Find Factors of Number
Find the Sum of Natural Numbers
Add Two Numbers
Find the Largest Among Three Numbers
Find Sum of Natural Numbers Using Recursion
Find the Factorial of a Number

TUTORIALS EXAMPLES COMPANY LEGAL

Python Tutorials Python Examples About Privacy Policy

C Tutorials C Examples Advertising Terms And Conditions

Java Tutorials Java Examples Contact App's Privacy Policy

Kotlin Tutorials Kotlin Examples App's Terms And Conditions

C++ Tutorials C++ Examples

Swift Tutorials R Examples

R Tutorials

Algorithms Tutorials

Copyright © Parewa Labs Pvt. Ltd. All rights reserved.

You might also like