0
Can someone tell me how to solve this. Project name: Generating...
Finding prime numbers is a common coding interview task. The given code defines a function isPrime(x), which returns True if x is prime. You need to create a generator function primeGenerator(), that will take two numbers as arguments, and use the isPrime() function to output the prime numbers in the given range (between the two arguments). Sample Input: 10 20 Sample Output: [11, 13, 17, 19] ⭐Sample code⭐: def isPrime(x): if x < 2: return False elif x == 2: return True for n in range(2, x): if x % n ==0: return False return True def primeGenerator(a, b): #your code goes here f = int(input()) t = int(input()) print(list(primeGenerator(f, t)))
3 Respostas
+ 1
Hi Navraj Singh. You first have to create an array or list that prints all the numbers between the inputs
# Python program to display all the prime numbers within an interval
small = int (input())
big = int (input ())
#operation started
for num in range(small, big + 1):
#since all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
+ 1
I hope this will help you, Navraj Singh
+ 1
def isPrime(x):
if x < 2:
return False
elif x == 2:
return True
for n in range(2, x):
if x % n ==0:
return False
return True
def primeGenerator(a, b):
#your code goes here
for number in range(a,b):
if isPrime(number):
yield number
f = int(input())
t = int(input())
print(list(primeGenerator(f, t)))