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)
2 Answers
+ 6
You could test the code in SL Playground with some info prints and see what happend.
+ 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