Nov-07-2022, 08:35 PM
(This post was last modified: Nov-07-2022, 08:35 PM by deanhystad.)
It has to do with how range() works. When you call range(start, end, step) the results includes start and numbers up to, but not including end.
The square root of 25 is 5. If I do "for x in range(3, 5, 2):" the only factor tested is 3. If I change that to "for x in range(3, 6, 2):" the code tests 3 and 5.
This is not a question you should be asking on this forum. This is a question you should be trying to figure out yourself. If I didn't know the answer I would write a program like this:
The square root of 25 is 5. If I do "for x in range(3, 5, 2):" the only factor tested is 3. If I change that to "for x in range(3, 6, 2):" the code tests 3 and 5.
This is not a question you should be asking on this forum. This is a question you should be trying to figure out yourself. If I didn't know the answer I would write a program like this:
number = 25 for i in range(3, int(number**0.5), 2): print(i, end=", ") print() for i in range(3, int(number**0.5)+1, 2): print(i, end=", ") print()
Output:3,
3, 5,
If you do research and perform experiments to answer these kinds of questions your Python knowledge will grow much faster than if you ask questions on the forum. I don't think you are learning much here. I think most of what we say is in one ear and out the other because you don't really understand much of what is said. That won't be the case when you are the one providing the answer. So feel free to ask questions, but only after you've made a significant effort to answer the question yourself. And when you do post, make sure you reference the work you've done.