Hi Janos,
Quote: Your logic is backward, and mine is the forward, isn't it? ;)
The Story of My Life!
--Terry
On Thu, 2007-07-05 at 07:30 +0200, János Juhász wrote:
>
> Hi Terry
>
> > "According to the Gregorian calendar, which is the civil calendar in
> use
> > today, years evenly divisib
"János Juhász" <[EMAIL PROTECTED]> wrote
>> def isLeapYear(y):
>> if y % 4 == 0: return True
> As it always return True, if y%4 == 0, there is problem with the
> exceptions
My original function had %400 not %4 so it worked.
>> if (y % 4 == 0) and not (y %100 == 0): return True
>> else: ret
Hi Terry
> "According to the Gregorian calendar, which is the civil calendar in use
> today, years evenly divisible by 4 are leap years, with the exception of
> centurial years that are not evenly divisible by 400."
> def isLeapYear(y):
> if y % 4 == 0: return True
As it always return True, if
"Terry" <[EMAIL PROTECTED]> wrote
> def isLeapYear(y):
>if y % 4 == 0:
>if y % 100 == 0 and y % 400 == 1:
>answer = False
>return answer
>answer = True
>return answer
>answer = False
>return answer
Not quite. y%400 == 1 will only be true
For anyone who was following this, here is the finished, non floating
point, program, after all the kind advice received has been incorporated
into it (hopefully I have the leap year logic right...):
# *** (7) MAIN BODY -- The Buck Starts Here! ***
def isLeapYear(y):
if y % 4 == 0
"Terry" <[EMAIL PROTECTED]> wrote
> Wow! Those changes radically change the program!
>
> Is there a way to get the try-exception to cause the
> end user questions to be repeated until acceptable
> answers are given?
Put the whole blocxk inside a while loop:
start = end = None
while start
Alan,
Wow! Those changes radically change the program!
Is there a way to get the try-exception to cause the end user questions
to be repeated until acceptable answers are given? Like a kind of
"return"
or "repeat" command that could be added to the except side of things?
try:
start = int(
"Terry" <[EMAIL PROTECTED]> wrote
> trapping for possible user errors.
> I am using x.isalnum() to check that I have a number
First, alnum() checks for alpha-numeric characters so
will allow both alphabetic characters and numerics.
BUT in python its better to ask forgiveness that permission
so
Ha Ha Ha It appears I was having a very blond day.
For some reason, I was mentally verbalizing to myself, each time I
looked at x.isalnum(), "X IS-ALL-NUMBERS",
instead of "X IS-Alpha-Numeric". I remember thinking..if one can
call it that., "I wonder why x.isdigit()
is singular for o
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Consider using something like:
try:
start, end = int(start), int(end)
except ValueError:
print "oops it was not a number."
Andreas
Terry wrote:
> Hi!
>
> I am running Python 2.5, and I have an IF statement in the below program
> that does n
Terry wrote:
> Hi!
>
Hi...
> I am using x.isalnum() to check that I have a number for each year
> entered, and it doesn't look to me like it is functioning properly.
That's because "x.isalnum()" will return True if "x" is not empty and
it's content are *either* an Alpha or a Number (which
Greetings,
Perhaps the first thing you should do, before checking
whether the user entered '' instead of '2000' is to
get the leap year function working properly.
Definition:
Leap years occur according to the following formula:
a leap year is divisible by four,
but not by one hu
Use isdigit instead of isalnum.
HTH,
Wolfram
On 03.07.2007 09:51, Terry wrote:
> Hi!
>
> I am running Python 2.5, and I have an IF statement in the below program
> that does not seem
> to be doing it's job. The program simply acquires a range of years from
> the user and prints out
> all the lea
Hi!
I am running Python 2.5, and I have an IF statement in the below program
that does not seem
to be doing it's job. The program simply acquires a range of years from
the user and prints out
all the leap years between the two dates. I am having trouble in
trapping for possible user
errors. I a
14 matches
Mail list logo