[Tutor] n.isalnum() is failing

Terry terry.kemmerer at gmail.com
Wed Jul 4 08:34:28 CEST 2007


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:
        if y % 100 == 0 and y % 400 == 1:
            answer = False
            return answer
        answer = True
        return answer
    answer = False
    return answer

print "This program finds all leap years between any two
dates.";print;print

start = end = None 
while start == None:
    try:
        start = int(raw_input("Enter yyyy for beginning year : "))
        end = int(raw_input("Enter yyyy for ending year : "))

    except ValueError:
        print;print "YEAR must be a integer number -- TRY AGAIN!"
        start = end = None

if 1 <= start < end:
    print; print
    for y in range(start, end + 1):
        answer = isLeapYear(y)
        if answer == True:
            print y, "--leap year!"

print "Done!"


*** EXECUTION ***
>>> 
This program finds all leap years between any two dates.


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


1900 --leap year!
1904 --leap year!
1908 --leap year!
1912 --leap year!
1916 --leap year!
1920 --leap year!
1924 --leap year!
1928 --leap year!
1932 --leap year!
1936 --leap year!
1940 --leap year!
1944 --leap year!
1948 --leap year!
1952 --leap year!
1956 --leap year!
1960 --leap year!
1964 --leap year!
1968 --leap year!
1972 --leap year!
1976 --leap year!
1980 --leap year!
1984 --leap year!
1988 --leap year!
1992 --leap year!
1996 --leap year!
2000 --leap year!
Done!
>>> 

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


More information about the Tutor mailing list