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)
5 odpowiedzi
+ 2
why last return True? in isPrime()?
+ 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)
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.
0
does anyone solved this case?
thxs :-)
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