Python - Generators Challenge | Sololearn: Learn to code for FREE!
+ 1

Python - Generators Challenge

Hi everyone. I would like to know if anyone has the correct answer to this challenge, because i have a solution which pass the first 3 tests, but not the last, and that one is hidden for not having a PRO account, and i dont know why it produces an error. This is my solution so far. Thanks 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 num in range(a, b+1): if isPrime(num): yield num f = int(input()) t = int(input()) print(list(primeGenerator(f, t)))

16th Jan 2024, 6:00 PM
Matttz
Matttz - avatar
3 ответов
+ 6
Matttz , the issue is the use of `+1` in the for loop in function `primeGenerator(...)`
16th Jan 2024, 6:54 PM
Lothar
Lothar - avatar
+ 4
Matttz , you are welcome ...
16th Jan 2024, 9:03 PM
Lothar
Lothar - avatar
+ 2
if lothar_answer == True : print("Thanks Lothar, you saved me!") xD
16th Jan 2024, 7:08 PM
Matttz
Matttz - avatar