In: Computer Science
5. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, how‐ ever, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Use the function in a program that prompts the user to enter a number then displays a message indicating whether the number is prime.
6. In another program, use the function you wrote in question 5 to print the prime numbers between 1 and 100 using for loop.
5. SOURCE CODE
def isPrime(n):
if n <= 1 or n % 1 > 0:
return False
for i in range(2, n//2):
if n % i == 0:
return False
return True
6. SOURCE CODE
def isPrime(n):
if n <= 1 or n % 1 > 0:
return False
for i in range(2, n//2):
if n % i == 0:
return False
return True
for i in range(1,101):
print(isPrime(i))
OUTPUT
False
True
True
True
True
False
True
False
False
False
True
False
True
False
False
False
True
False
True
False
False
False
True
False
False
False
False
False
True
False
True
False
False
False
False
False
True
False
False
False
True
False
True
False
False
False
True
False
False
False
False
False
True
False
False
False
False
False
True
False
True
False
False
False
False
False
True
False
False
False
True
False
True
False
False
False
False
False
True
False
False
False
True
False
False
False
False
False
True
False
False
False
False
False
False
False
True
False
False
False
OUTPUT SCREENSHOT
Comment bellow for any doubts