+ 5

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)))

8th Jul 2021, 5:15 PM
Zach Z
14 ответов
+ 3
Zach 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.
12th Jul 2021, 6:59 PM
JaScript
JaScript - avatar
+ 4
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.
11th Jul 2021, 5:08 PM
JaScript
JaScript - avatar
+ 4
Super. Happy coding Zach Z
14th Jul 2021, 6:23 PM
JaScript
JaScript - avatar
+ 3
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]
8th Jul 2021, 5:21 PM
Zach Z
+ 2
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)))
9th Jul 2021, 6:43 PM
Zach Z
+ 2
def is_prime(n): if n <= 1: return False else: for i in range(2, n): if n % i == 0: return False return True
9th Jul 2021, 8:05 PM
JaScript
JaScript - avatar
+ 2
Appreciate the attempt but that doesnt work either JaScript. Also should be ‘isPrime’. Angelo or Ja, any other ideas?? Thanks
10th Jul 2021, 7:36 PM
Zach Z
+ 2
Zach Z please tell exactly what in this following code does not work? https://code.sololearn.com/cNv8HCwWWydd/?ref=app
10th Jul 2021, 8:08 PM
JaScript
JaScript - avatar
+ 2
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.
11th Jul 2021, 4:34 PM
Zach Z
+ 1
It should be something like for i in range(a, b+1): if isPrime(i): yield i
8th Jul 2021, 6:38 PM
Angelo
Angelo - avatar
+ 1
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.
12th Jul 2021, 4:14 PM
Zach Z
+ 1
Zach Z does it show you the input?
12th Jul 2021, 4:38 PM
Angelo
Angelo - avatar
+ 1
It wasnt saying was was wrong, it doesnt show some test cases. Now it worked for test case 4. Wasnt before. Thanks! JaScript
13th Jul 2021, 9:06 PM
Zach Z
+ 1
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)))
23rd Feb 2022, 6:15 AM
Erfan Ebrahimi
Erfan Ebrahimi - avatar