📘 Lesson · Lesson 73
Prime Number Program
Prime Number Program in Python
A prime number is divisible only by 1 and itself. This program checks if a given number is prime.
Python Program
Python
n = 13
is_prime = True
if n < 2:
is_prime = False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
is_prime = False
break
print(n, "is Prime" if is_prime else "is Not Prime")Expected Output
13 is Prime
How it Works
- We check divisors from 2 up to the square root of n (faster).
- If any divisor divides n exactly, it is not prime.
- Numbers below 2 are not prime.
Summary
- A prime number is divisible only by 1 and itself. This program checks if a given number is prime.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.