[Tutor] [Fwd: [Fwd: Re: n.isalnum() is failing]]

Terry terry.kemmerer at gmail.com
Tue Jul 3 22:10:57 CEST 2007


Hi Bhaaluu,

I have misled you. I am working on a section ABOVE the program I showed,
that I am thinking to 
have my most used elements in, left in a state of being # remarks. In
other words, I am thinking 
of creating a set of most used CONVENTIONS and leave them as a blank
file. Thus, when I need 
to write a new program, I just grab the blank CONVENTIONS, and rename it
to my newest program 
name. I have no idea if this is a good idea or not, it is just how I
used to start a program in BASIC 
25 years ago.....or so.

What you didn't see, was the following line which I had enable in the
Conventions area and 
neglected to conscientiously reveal:

from __future__ import division

With that line enabled, my divisions are floating point, rather than
integer, and using the same 
years you did, my program yields the following results:

>>> 
This program finds all leap years between two dates.


Enter yyyy for beginning year : 1995
Enter yyyy for ending year : 2000


1996 -- leap year!
2000 -- leap year!
Done!
>>> 

I admit, I have never seen the "%" operator before. I should probably
learn to 
use it.....but I had felt this overpowering need wash over me to get it
done and 
see it happen without spending more time researching. It was one of
those 
primal things where you have this need to do more than you can. So,
instead,
I was using the  "t1 == int(t1)" type compare, that I learned in BASIC
about 
25 years ago, to discover a remainder or no. My blond brain is currently
thinking 
that works....but the day is young. And maybe "%" is faster?
        
Have a great day!

-------- Forwarded Message --------
From: bhaaluu <bhaaluu at gmail.com>
To: Terry <terry.kemmerer at gmail.com>, Tutor at python.org
Subject: Re: [Tutor] n.isalnum() is failing
Date: Tue, 3 Jul 2007 05:06:20 -0400


Greetings,

Perhaps the first thing you should do, before checking
whether the user entered 'aaaa' 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 hundred,
       unless it is divisible by four hundred.

I find that definition to be a wee bit misleading.
This might help:

A leap year is divisible by four, with a REMAINDER of zero.
The remainder of a division is found in python with the "%" operator.
So you might want to check and see IF the remainders are zero or one,
TRUE or FALSE.

When I run your program, entering two four-digit years,
this is the output:

This program finds all leap years between two dates.

Enter yyyy for beginning year : 1995
Enter yyyy for ending year : 2000

1995 -- leap year!
1996 -- leap year!
1997 -- leap year!
1998 -- leap year!
1999 -- leap year!
2000 -- leap year!
Done!

Since we know that ALL of those years can't be leap years,
it means that your leap() function isn't doing something right?
I suggest that you get leap() working properly first, then tackle
the other problem.

Cheers!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070703/3a07bbcb/attachment.html 


More information about the Tutor mailing list