On Tue, 15 May 2007, Kent Johnson wrote:
> Matt Smith wrote:
> >
> > Thanks for the help. For future reference how do I go look at the
> > implementation of a particular function (the ones coded in Python, I
> > don't know C)?
>
> Look in the lib directory that was installed with Python. The loc
Hey Matt,
Matt Smith wrote:
> I guessed that there would be a module out
> there providing a function to do this but wanted to go through the
> process as a learning exercise.
Good form, old boy.
> Here is the final code I have come up with, any comments?
I think your code looks fine. I like to
Matt Smith wrote:
>> Here is the implementation of calendar.isleap():
>>
>> def isleap(year):
>> """Return 1 for leap years, 0 for non-leap years."""
>> return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
>
> Hi Kent,
>
> Thanks for the help. For future reference how do I go l
Matt Smith wrote:
> ere is the final code I have come up with, any comments?
>
> # A program to determine whether a year is a leap year or not
>
> def is_leap_year(year):
> # Function that accepts a year as input and returns true if it is a leap
> year, false if it is not
> if year % 4 == 0 a
Hi,
Thanks for all the help, I guessed that there would be a module out
there providing a function to do this but wanted to go through the
process as a learning exercise. The modulus operator was just what I was
looking for, I had been trying to check for a difference between the
division and the
Eric Walstad wrote:
> Hey Matt,
>
> Skirting your question that looks like a modulo issue[1]...
>
> Maybe isleapyear[2] will work for you:
>
> import calendar
>
> calendar.isleap(2007) -> False
> calendar.isleap(2008) -> True
And one of the nice things about Python, as well as having lots of
"Bob Gailer" <[EMAIL PROTECTED]> wrote
>> Matt: I'm not sure about your pseudocode, but have you tried to
>> accomplish this with the modulus operator?
>> It provides the remainder of integer division
> No, it provides the modulus, and applies to float not just integer!.
While modulus is techni
Luke Paireepinart wrote:
> Matt Smith wrote:
>
>> Hi there,
>>
>> I'm trying to write a short function to test whether a year is a leap
>> year or not. To do this I need to check whether the year divides exactly
>> by 4, 100 and 400. I can't think of an easy way to test whether there is
>> a rem
On 15/05/07, Arthur Coleman <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I believe it should be if !(year % 4) or !(year % 100) or !(year % 400)
FWIW, the correct leapyear test is:
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
# then year is a leap year
Year 2100 will not be a leap ye
Subject: Re: [Tutor] How to test for a remainder from division
Matt Smith wrote:
> Hi there,
>
> I'm trying to write a short function to test whether a year is a leap
> year or not. To do this I need to check whether the year divides exactly
> by 4, 100 and 400. I can't thi
On Mon, May 14, 2007, Luke Paireepinart wrote:
>Matt Smith wrote:
>> Hi there,
>>
>> I'm trying to write a short function to test whether a year is a leap
>> year or not. To do this I need to check whether the year divides exactly
>> by 4, 100 and 400. I can't think of an easy way to test whether t
Hey Matt,
Skirting your question that looks like a modulo issue[1]...
Maybe isleapyear[2] will work for you:
import calendar
calendar.isleap(2007) -> False
calendar.isleap(2008) -> True
I hope that helps,
Eric.
[1] http://docs.python.org/ref/binary.html
[2] http://docs.python.org/lib/modul
Matt Smith wrote:
> Hi there,
>
> I'm trying to write a short function to test whether a year is a leap
> year or not. To do this I need to check whether the year divides exactly
> by 4, 100 and 400. I can't think of an easy way to test whether there is
> a remainder or not. The best I can come up
Hi there,
I'm trying to write a short function to test whether a year is a leap
year or not. To do this I need to check whether the year divides exactly
by 4, 100 and 400. I can't think of an easy way to test whether there is
a remainder or not. The best I can come up with so far is:
if (year / 4
14 matches
Mail list logo