0

Python Intermediate Generators question:

The task is to to take two inputs which have to be numbers and output a list of all primenumber in the given range. For some reason I am not able to determine Test 4 fails, while 1 - 3 succeed. Here is what I've got so far: 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): Mylist=[] for i in range (a,b+1): if isPrime(i) == True: Mylist.append(i) print(Mylist) f = int(input()) t = int(input()) primeGenerator(f, t)

16th Mar 2021, 11:30 AM
Guiscardo
5 odpowiedzi
+ 2
why last return True? in isPrime()?
16th Mar 2021, 11:31 AM
Sharique Khan
Sharique Khan - avatar
+ 1
u can try this lower = int(input("Enter lower range: ")) upper = int(input("Enter upper range: ")) for num in range(lower,upper + 1): if num > 1: for i in range(2,num): if (num % i) == 0: break else: print(num)
16th Mar 2021, 12:21 PM
Sharique Khan
Sharique Khan - avatar
0
Because it is a prime number if the if-clause does not retrun a false. BTW: The isPrime Function was given a part of the task, so I did not write this myself.
16th Mar 2021, 11:55 AM
Guiscardo
0
does anyone solved this case? thxs :-)
30th Sep 2023, 6:10 PM
giovanni caiazzo
giovanni caiazzo - avatar
0
your error is on this line: for i in range (a,b+1): <---- why did you put. " +1 " the correct answer is without +1
3rd Oct 2023, 1:21 AM
Jairo Terán Vela
Jairo Terán Vela - avatar