0

why doesn't work my code

def isPrime(x): if x <= 1: return False if x <= 3: return True if x % 2 == 0 or x % 3 == 0: return False i = 5 while i * i <= x: if x % i == 0 or x % (i + 2) == 0: return False i += 6 return True def primeGenerator(start, end): for num in range(max(2, start), end + 1): if isPrime(num): yield num # Vraag de gebruiker om waarden voor start en end in te voeren start = int(input()) end = int(input()) # Maak een lijst van de priemgetallen in het opgegeven bereik prime_numbers = list(primeGenerator(start, end)) # Toon de resultaten print(prime_numbers)

18th Sep 2023, 10:50 AM
veuge de3draken
veuge de3draken - avatar
2 Answers
+ 6
You could test the code in SL Playground with some info prints and see what happend.
18th Sep 2023, 11:01 AM
JaScript
JaScript - avatar
+ 1
Hi, veuge de3draken ! Your code looks correct and functions as intended! I’m genuinely impressed with how you’ve structured it. If you’re seeking further optimizations, especially when generating a list of prime numbers, you might be interested in exploring the “Sieve of Eratosthenes”. It’s one of the most efficient methods to quickly generate prime numbers up to a certain value. Regardless, great job with your current code! https://sololearn.com/compiler-playground/cCp4woK8jhH8/?ref=app
18th Sep 2023, 8:17 PM
Per Bratthammar
Per Bratthammar - avatar