0

Need help

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): prime_numbers = [] for num in range(a, b + 1): if isPrime(num): prime_numbers.append(num) return prime_numbers f = int(input()) t = int(input()) print(primeGenerator(f, t))

12th Sep 2023, 9:18 PM
mustafa mustaf
mustafa mustaf - avatar
4 odpowiedzi
+ 5
mustafa mustaf , make also sure that the for loop in the `primesGenerator(...)` function is like: ... for num in range(a, b): # <<< upper bound should not be included ...
13th Sep 2023, 11:42 AM
Lothar
Lothar - avatar
+ 1
What's it that you need help with?
13th Sep 2023, 4:06 AM
Divine Darkey
Divine Darkey - avatar
+ 1
mustafa mustaf , Please remove your old tags, and add these: python, generator, help I recognize that code. It's from: "Python Developer" course "Functional Programming" module "Generators" practice Most of the code is pre-written by Sololearn, including the first line of the generator function. You only have to provide the indented statements for the body of the generator function. You modified the print statement and maybe more. You should use Reset Code and rebuild the generator body without changing anything else. Inside the generator, make a loop that tests the numbers in the range, as you started, but don't build the list inside the generator. Use yield inside the loop to yield one number at a time if it is prime. (A generator function must include a yield statement.) The list will get built in the print statement that calls the generator and receives the yielded primes. Sololearn's generator explanation is thin, so also do a web search for better explanations.
13th Sep 2023, 5:53 AM
Rain
Rain - avatar
0
Nothing is wrong your code, the code itself is correct, try using a different python editor (if you have a pc, run the code in vscode or there are python editors you can download on the play store), sololearn's editor is sub-optimal. Hope that helps
14th Sep 2023, 7:30 PM
Habeeb Salami
Habeeb Salami - avatar