Python Intermediate Generators question: | Sololearn: Learn to code for FREE!

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)

3/16/2021 11:30:15 AM

Guiscardo

3 Answers

New Answer

+1

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.