0
What is going on here?
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): #your code goes here f = int(input()) t = int(input()) print(list(primeGenerator(f, t))) This is a problem from the python intermediate course. This line in the isPrime function is simply not explained: for n in range(2, x): Why are there two numbers in the parentheses? What is going on in this line? n is being given the values of 2 and x? 2 then x? What is going on here?
4 Antworten
+ 7
The 'range' function can take up to 3 parameters: start, stop, and step.
'x' represents the stop in the code above.
https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-range-function/amp/
+ 2
21kHzBANK21kHZ ,
Go to this page anytime you want to look up something like range and get the official description, which should be every time Sololearn introduces a new term.
https://docs.python.org/3/genindex.html
+ 1
Thank you so much for the help Keith. I can't even move on in the Python courser unless I understand this o pay for premium and have the answer spoonfed to me, it's so stupid. The stop start an step aspects of range were never explained in any caliber yet I need to understand them to finish the course 🙄
+ 1
you can do a google search for things you don't understand. There are also plenty of other free tutorial sites, and there are books. Don't limit yourself on Sololearn's material.
I found that having the ability to look for answers is ultimately the bigger skill in learning to code than just memorizing the syntax and procedures.