remainder of dividing by zero
MRAB
python at mrabarnett.plus.com
Thu Apr 12 19:54:24 EDT 2012
On 12/04/2012 23:34, Ethan Furman wrote:
> Okay, so I haven't asked a stupid question in a long time and I'm
> suffering withdrawal symptoms... ;)
>
> 5 % 0 = ?
>
> It seems to me that the answer should be 5: no matter how many times we
> add 0 to itself, the remainder of the intermediate step will be 5.
>
> Is there a postulate or by definition answer as to why this should not
> be so?
>
If x > 0, 0 <= 5 % x < x.
At the limit of x == 0, you get 0 <= 5 % 0 < 0.
At that point, an exception is probably a good idea! :-)
More information about the Python-list
mailing list