MRAB wrote:
>> if ( x % 4 ) == 0:
>> whatever # x is divisible by 4
>>
>> modulus is your friend :)
>>
>> -smithj
>
>
> It's "modulo"; "modulus" is a different operation.
>
>
Wikipedia says "modulus may refer to... %, the modulo operator of
various programming languages"
http://en.wikip
Jonathan Smith wrote:
> > <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >> 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
> >>
> >> Just seems a
CTED]>
To: python-list@python.org
Date: 5 Dec 2006 11:26:49 -0800
Subject: Re: Ensure a variable is divisible by 4
Paul Rudin wrote:
Max M <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] skrev:
>> Nick Craig-Wood wrote:
>>> [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Paul Rudin wrote:
> Max M <[EMAIL PROTECTED]> writes:
>
> > [EMAIL PROTECTED] skrev:
> >> Nick Craig-Wood wrote:
> >>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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 do
Max M <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] skrev:
>> Nick Craig-Wood wrote:
>>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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
[EMAIL PROTECTED] skrev:
> Nick Craig-Wood wrote:
>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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
;-)
--
Nick Craig-Wood wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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
>
> You should use // for future compatibilit
> <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> 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
>>
>> Just seems a bit clunky to me.
if ( x % 4 ) == 0:
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>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
>
> Just seems a bit clunky to me.
>
All numbers are divisible by 4.
On 2006-12-04, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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
if x & 3:
print "not divisible by 4"
x &= ~3
print "it is now: x = %d"
If you want to round to nearest power of 4 rather
[EMAIL PROTECTED] <[EMAIL PROTECTED]> 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
You should use // for future compatibility which is guaranteed to be
an intege
[EMAIL PROTECTED] 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
>
> Just seems a bit clunky to me.
>
Depends what you mean by 'make it divisable'. Do you want to ch
> 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
>
> Just seems a bit clunky to me.
You're right...you'll want to read up on the "modulo" operator:
if x % 4 <> 0:
pri
[EMAIL PROTECTED] 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
>
> Just seems a bit clunky to me.
if x % 4 == 0:
# x is divisible by 4
George
--
http://mail.pyt
[EMAIL PROTECTED] 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
>
> Just seems a bit clunky to me.
>
Use modulo operator '%'
if not x % 4:
#
# Arrive here if
[EMAIL PROTECTED] schrieb:
> 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
>
> Just seems a bit clunky to me.
Division with rest:
>>> x % 4
3
--
http://mail.python.org/m
16 matches
Mail list logo