Re: [Tutor] How to test for a remainder from division

2007-05-15 Thread Terry Carroll
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

Re: [Tutor] How to test for a remainder from division

2007-05-15 Thread Eric Walstad
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

Re: [Tutor] How to test for a remainder from division

2007-05-15 Thread Kent Johnson
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

Re: [Tutor] How to test for a remainder from division

2007-05-15 Thread Kent Johnson
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Matt Smith
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Kent Johnson
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Alan Gauld
"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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Bob Gailer
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread John Fouhy
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Arthur Coleman
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Bill Campbell
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Eric Walstad
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

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Luke Paireepinart
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

[Tutor] How to test for a remainder from division

2007-05-14 Thread Matt Smith
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