[Tutor] How to test for a remainder from division
Kent Johnson
kent37 at tds.net
Tue May 15 12:26:53 CEST 2007
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 and (year % 100 != 0 or year % 400 == 0):
> return True
> else:
> return False
There is no need for the if statement, you can return the result directly:
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
Kent
>
> # Main program logic
> year = raw_input("What year? ")
> year = int(year)
> if is_leap_year(year):
> print year, "is a leap year."
> else:
> print year, "is not a leap year"
>
> Thanks,
>
> Matt
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list