Because (size+1)/2
could theoretically have a fractional part, Python always returns a floating point number from it. range
doesn't accept floats because there is no general way to turn it into an integer without potentially losing information. Neither of these steps special-cases the particular inputs that don't trigger these problems.
You don't care about those things, because you consider size
being even to be an invalid input. But Python doesn't know you don't care about the potential data loss unless you tell it - which you can do like this:
(size + 1) // 2
This removes the fractional part of the number, and only gives you the integer part (ie, rounded toward minus infinity).