0
help me to solve the issue.primegeneator code has passing 3 testcases output of 4.4 th test case hidden.
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 g=[] for i in range(a,b+1): if isPrime(i): yield i f = int(input()) t = int(input()) print(list(primeGenerator(f, t)))
3 Réponses
+ 3
Voonna Gowri Ganesh ,
The trick on that one is not to test the high input.
For example, the primes in range(5, 11) are 5 and 7, not 11. So don't try to include 11 by adding 1 like range(5, 11+1).
The variable names f and t mean from and to, but the to is not included.
+ 2
Voonna Gowri Ganesh you added an elif which I believe is where the error arrived. This should correct it.
def isPrime(x):
if x < 2:
return False
else:
for n in range(2, x):
if x % n == 0:
return False
return True
def primeGenerator(a, b):
for i in range(a, b ):
if isPrime(i):
yield i
f = int(input())
t = int(input())
print(list(primeGenerator(f, t)))
+ 2
Thank you