Hi, I've just started learning Python today, and I'm running into a little bump testing my leap year program (yes, the next step beyond hello world
)...
At the commented line in the middle (the second print statement), if I uncomment it I get an Internal 500 server error, which I've determined means I messed something up in the script. As far as I can tell, there shouldn't be anything wrong with having two print statements in an if: clause... is there?
Thanks!
)...Code:
#! /usr/bin/python
import cgi, re
from sys import exit
print "Content-Type: text/html\n\n"
form = cgi.FieldStorage()
if not form.has_key("year"):
print "No year specified!"
sys.exit(0)
y = form.getvalue("year")
if re.compile("^-?\d+$").search(y):
print "Year must be numeric! To represent years B.C., "
# print "use negative numbers, i.e. -133 for 133 B.C.
sys.exit(0)
year = int(y)
if year == 0:
print "Year 0 does not exist!"
sys.exit(0)
print year
if (year % 400) == 0:
print " is "
elif (year % 100) == 0:
print " is not "
elif (year % 4) == 0:
print " is "
else:
print " is not "
print "a leap year"
Thanks!
Comment