+ 1

can someone please explain this for me by writing comment on each and send to me 🙇🙇🙇

It output the prime numbers from the given range the user input, eg: first input=2 second input=20, output is =[2,3,5,7,,11,13,17,19] https://code.sololearn.com/cx5JMEa2rC0W/?ref=app

13th Aug 2022, 8:35 PM
Emmanuel Odukoya
Emmanuel Odukoya - avatar
4 Answers
+ 3
def isPrime(x): if x < 2: # number lessthan 2 , not prime return False elif x == 2: #number 2 prime return True for n in range(2, x): # from 2,x if it is divisable by any number n , then its not prime if x % n ==0: return False return True def primeGenerator(a, b): #your code goes here for number in range(a,b): #loop runs from a,b-1 values if isPrime(number): # if number is prime yield number # returns number to call f = int(input()) #input t = int(input()) #call the function primeGenerator with parameters f,t inputs , convert the returns values into list and display list print(list(primeGenerator(f, t))) # return causes to come out of function. where as yeild return value and continue execute next instruction.. hope it helps..
13th Aug 2022, 8:52 PM
Jayakrishna 🇮🇳
+ 1
Thank you very much i appreciate but can u tell me what the 'return True' at the end of the 'isprime' function stands for..
13th Aug 2022, 10:16 PM
Emmanuel Odukoya
Emmanuel Odukoya - avatar
+ 1
If non of if condition is true then it does not return a value. You need to return true if number is not < 2, not equal to 2, and also not evenly divisable by 2, n-1. Take ex: 7, It is not less than 2, not equal to 2, not divisable by 2, to 7-1 so all if conditions you have are failed. It means it prime so should return true. That's what does by return true and end. Hope it clears..
14th Aug 2022, 10:15 AM
Jayakrishna 🇮🇳
+ 1
Thank you so much bro u did Good
14th Aug 2022, 1:15 PM
Emmanuel Odukoya
Emmanuel Odukoya - avatar