Ensure a variable is divisible by 4

John Machin sjmachin at lexicon.net
Tue Dec 5 14:26:49 EST 2006


Paul Rudin wrote:
> Max M <maxm at mxm.dk> writes:
>
> > geskerrett at hotmail.com skrev:
> >> Nick Craig-Wood wrote:
> >>> geskerrett at hotmail.com <geskerrett at hotmail.com> wrote:
> >>>>  I am sure this is a basic math issue, but is there a better way to
> >>>>  ensure an int variable is divisible by 4 than by doing the following;
> >>>>
> >>>>  x = 111
> >>>>  x = (x /4) * 4
> >
> > X *= 4
> >
> > ;-)
> >
>
>
> x=4
> 
> :)

Ensure x is divisible by *any* non-zero integer:

x = 0

:-O




More information about the Python-list mailing list