@lakshayarora7/# SalmonNegativeCow

Files

- main.py

main.py

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

```
# PRIME NUMBER OR NOT
# A program to check whether the provided number is prime or not. The program should contain two functions: one for concluding whether a number is prime or not; the other a main program that reads a number and displays the conclusion.
# A prime number is an integer greater than 1 that is only divisible by one and itself e.g. 2, 3, 5, 7, 11, 3, 17, 19 etc.
# INPUT: any number
# OUTPUT: conclusion if the given number is prime or not
# Also, ensure that your file when imported into another file doesn't trigger your program automatically
# THOUGHT PROCESS: Construct a function that takes an argument, and returns True or False based on logic ->
# Declare a main function(call it anything you want) and have the user input a number ->
# Pass the number to the declared function ->
# Based on the value returned by the function, display the conclusion ->
# include the bit to run the main function if the file has not been imported i.e. it has been run directly.
# function to determine whether the supplied number is prime or not.
def isPrime(num):
if num <= 1:
return False
for factor in range(2, num): # if there exists any number greater than 2 that
if num % factor == 0: # divides the given number evenly(with remainder 0, that is),
return False # then the given number is not prime
return True
# the main function
def mainProgram():
number = int(input("Enter the number to be tested: "))
if isPrime(number):
print(number, "is prime.")
else:
print(number, "is not prime.")
# if the file has been run directly AND not been imported, call the main function
if __name__ == "__main__":
mainProgram()
# for repl.it
mainProgram()
```