The terminating condition a + b <= i
is equivalent to b <= i - a
which in turn (as Python for
uses less than not less than or equal) would be b < i - a + 1
.
That means in Python you could write:
for b in range((i - a) / 2, i - a + 1):
...
But very often you don’t want to write like for like when converting from C/C++ to Python. You may be better to restructure the code entirely.
1
solved How to write a for loop in python [closed]