[Tutor] Help Return's are confusing me

Don Arnold darnold02@sprynet.com
Wed, 9 Oct 2002 18:43:41 -0500


----- Original Message -----
From: "Gregor Lingl" <glingl@aon.at>
To: "python" <python@inkedmn.net>
Cc: "Peter Dudleston" <dandudle@msn.com>; <tutor@python.org>
Sent: Wednesday, October 09, 2002 6:12 PM
Subject: Re: [Tutor] Help Return's are confusing me


> python schrieb:
>
> >peter,
> >
> >ok, it works like this...
> >
> >in the example you posted, there are two return statements.  it might
> >have been better written like this:
> >
> >def julian_leap(y):
> >     if (y%4) == 0:
> >        return 1  #is returned if the conditional is true
> >     else:
> >        return 0  #is returned if the conditional is false
> >
> >
> >
>
> Why not:
>
> def julian_leap(y):
>     return y%4 == 0
>
> Regards, Gregor
>
>

because it's wrong? ; )  a year divisible by 100 isn't a leap year unless
it's divisible by 400. so:

def julian_leap(y):
    return (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0)

Don