# Intermediate Python - 14.2 Practice help - “Generating…”

See question in comments. Sample Input 10 20 Sample Output [11, 13, 17, 19] ——————— Current code: 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): for i in isPrime(x): if i == x: return i f = int(input()) t = int(input()) print(list(primeGenerator(f, t)))

7/8/2021 5:15:22 PM

Zach Z14 Answers

New AnswerZach Z I have had another idea and changed in the generator function the loop on: for i in range(a, b): Please try again and let us know what happend.

Question: Finding prime numbers is a common coding interview task. The given code defines a function isPrime(x), which returns True if x is prime. You need to create a generator function primeGenerator(), that will take two numbers as arguments, and use the isPrime() function to output the prime numbers in the given range (between the two arguments). Sample Input 10 20 Sample Output [11, 13, 17, 19]

Zach Z here was no any errors showed. Unfortunately I have not pro account. But I have for you the code now completely new saved. Please copy this and try again and let me know about the result.

JaScript that was the current attempt. This is the updated. Still isnt working for the 4th and final scenario. 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): for i in range(a, b+1): if isPrime(i): yield i f = int(input()) t = int(input()) print(list(primeGenerator(f, t)))

def is_prime(n): if n <= 1: return False else: for i in range(2, n): if n % i == 0: return False return True

Appreciate the attempt but that doesnt work either JaScript. Also should be ‘isPrime’. Angelo or Ja, any other ideas?? Thanks

Zach Z please tell exactly what in this following code does not work? https://code.sololearn.com/cNv8HCwWWydd/?ref=app

JaScript whatever you just sent back has an error on line 3 with indentations/spaces. But idk, it doesnt say what the issue was with the other, just that it doesnt solve test case 4 (which is hidden). So it wont complete it.

JaScript ya still doesnt solve #4. Not sure what the issue is. Even with a pro account, it doesnt show me what the error is or even the output expected.

It wasnt saying was was wrong, it doesnt show some test cases. Now it worked for test case 4. Wasnt before. Thanks! JaScript

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(x,y): for i in range(x,y): if isprime(i)==True: yield i x=int(input()) y=int(input()) if x>y: print(list(primeGenerator(y,x))) else: print(list(primeGenerator(x,y)))