Prime Numbers from n to m in Python
In [1]:import math
n = int (input ('Enter the value of n: '))
m = int (input ('Enter the value of m: '))
if n > m: #Swapping n and m is n is greater than m
temp = n
n = m
m = temp
print('Available Prime Numbers between ', n, ' and ', m, 'are: ')
for i in range(n, m + 1):
isPrime = True
if i <= 1:
isPrime = False
else:
for j in range(2, int(math.sqrt(i))):
if i % j == 0:
# print (i)
isPrime = False
if isPrime == True:
print (i, end = ', ')
Enter the value of n: 1
Enter the value of m: 100
Available Prime Numbers between 1 and 100 are:
2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 23, 25, 29, 31, 35, 37, 41, 43, 47, 49, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
In [1]:
import math
n = int (input ('Enter the value of n: '))
m = int (input ('Enter the value of m: '))
if n > m: #Swapping n and m is n is greater than m
temp = n
n = m
m = temp
print('Available Prime Numbers between ', n, ' and ', m, 'are: ')
for i in range(n, m + 1):
isPrime = True
if i <= 1:
isPrime = False
else:
for j in range(2, int(math.sqrt(i))):
if i % j == 0:
# print (i)
isPrime = False
if isPrime == True:
print (i, end = ', ')
Enter the value of n: 1 Enter the value of m: 100 Available Prime Numbers between 1 and 100 are: 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 23, 25, 29, 31, 35, 37, 41, 43, 47, 49, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
No comments:
Post a Comment