Python Intermediate 14.2 Practice | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python Intermediate 14.2 Practice

The instructions say to generate prime numbers "between" the inputs. But, since it uses the range(a,b), wouldn't it include 'a' but not 'b'? If the input was 5 17 then this code would return [5, 7, 11, 13] but not 17. Shouldn't it use for i in range(a+1,b): Here's the code that is listed as the solution: 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): #your code goes here for i in range(a,b): if isPrime(i): yield i f = int(input()) t = int(input()) print(list(primeGenerator(f, t)))

12th Apr 2022, 5:26 AM
April Foster
4 Answers
0
"Between" is generally interpretted as including both `a` as well as `b` i.e [a, b] and not (a, b) as per my understanding
12th Apr 2022, 5:34 AM
Infinity
Infinity - avatar
0
Here in for loop of primeGenerator You took only b In python for loop it takes values upto n-1 only so inorder to link n we should mention n+1 So in ur code inorder to include b you should take b+1 Once look at this code https://code.sololearn.com/cV808GjI2Orm/?ref=app
12th Apr 2022, 5:45 AM
UNKNOWN
0
Please avoid writing links in the post's tags. Not only they won't work, they ruin the search engine work which leads to less accuracy. https://code.sololearn.com/W3uiji9X28C1/?ref=app
12th Apr 2022, 9:51 AM
Ipang
0
This appears indeed to be wrong (or at least grossly misleading). The given solution will pass sololearn's test cases anyway as long as none of them uses a prime number as upper limit. The reason is that sololearn does not check the code. Instead it merely compares the output with the expected output. Since sololearn introduced model solutions only recently it is quite possible that this is an error that has gone unnoticed so far. You should send a bug report (ideally including screenshots) to [email protected].
12th Apr 2022, 5:56 PM
Simon Sauter
Simon Sauter - avatar