This content was proof-read by Grammarly. You can Try Grammary for FREE
This Python program explains how you can print prime numbers in a given interval in python using loops.
A number is a prime number if the following conditions are satisfied
Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book
- It is a Positive Number
- It is Greater than 1.
- Has no other factors except 1 and the number itself.
Some of the examples of a prime number are 2,3 etc.
How to Print Prime Numbers in a given interval in Python?
# Author : Abandantcode.com # Python program to display prime numbers within a given interval minRange = 1 maxRange = 10 print("Prime numbers") for num in range(minRange, maxRange + 1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: print(num)
In the above python program, we store the intervals in the minRange and maxRange variables and find the prime numbers between this range using the for loop and the modulus operatos in python.