Include upper bound in range()
Posted
by Jull
on Stack Overflow
See other posts from Stack Overflow
or by Jull
Published on 2010-05-07T00:09:45Z
Indexed on
2010/05/07
0:18 UTC
Read the original article
Hit count: 101
python
How can I include the upper bound in range() function? I can't add by 1 because my for-loop looks like:
for x in range(1,math.floor(math.sqrt(x))):
y = math.sqrt(n - x * x)
But as I understand it will actually be 1 < x < M
where I need 1 < x <= M
Adding 1 will completely change the result.
I am trying to rewrite my old program from C# to Python. That's how it looked in C#:
for (int x = 1; x <= Math.Floor(Math.Sqrt(n)); x++)
double y = Math.Sqrt(n - x * x);
© Stack Overflow or respective owner