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
8/13/2022 8:35:08 PMEmmanuel Odukoya
4 AnswersNew Answer
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..
Thank you very much i appreciate but can u tell me what the 'return True' at the end of the 'isprime' function stands for..
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..
Thank you so much bro u did Good