Created
November 12, 2021 04:59
-
-
Save moulik-source/bbed7fc101ceb93537557aac22e11e6a to your computer and use it in GitHub Desktop.
prime number
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
# 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment