-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2.py
31 lines (23 loc) · 1.01 KB
/
p2.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
'''2. To find all prime numbers within a given range.'''
'''
Prime number ->
A number is greater than 1 is called a prime number,
if it has only two factors, namely 1 and the number itself.
'''
def check_prime(num):
''' check if num is Prime or not '''
if num > 1:
is_prime = True # assuming the number is prime number
for i in range(2, num): # looping between 2 and num
if (num % i) == 0: # if number (i) completely divides num, then num is not a prime no.
is_prime = False # if any no (i) can divide num, it means it isn't prime
return is_prime # else it is prime
return False # if number is less than 1 return False.
if __name__ == '__main__':
print("Enter the lower limit: ")
lower_limit = int(input())
print("Enter the upper limit: ")
upper_limit = int(input())
for num in range(lower_limit, upper_limit):
if check_prime(num) == True:
print(num)