-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Python Program to Check Prime Number.py
- Loading branch information
1 parent
47eff2c
commit 98b49ca
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Program to check if a number is prime or not | ||
|
||
num = 29 | ||
|
||
# To take input from the user | ||
#num = int(input("Enter a number: ")) | ||
|
||
# define a flag variable | ||
flag = False | ||
|
||
# prime numbers are greater than 1 | ||
if num > 1: | ||
# check for factors | ||
for i in range(2, num): | ||
if (num % i) == 0: | ||
# if factor is found, set flag to True | ||
flag = True | ||
# break out of loop | ||
break | ||
|
||
# check if flag is True | ||
if flag: | ||
print(num, "is not a prime number") | ||
else: | ||
print(num, "is a prime number") |