Learning Python, having a bit of trouble

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dr. Jones
    Junior Member
    • Apr 2007
    • 11

    Learning Python, having a bit of trouble

    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 )...

    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"
    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!
  • AndrewT
    Administrator
    • Mar 2004
    • 3653

    #2
    I'm no Python pro but it looks like you missing an end quote at the end of the commented out print statement.

    Comment

    • Dr. Jones
      Junior Member
      • Apr 2007
      • 11

      #3
      I feel like an idiot... that seems to have done the trick >_>

      That's why it's good to have a second pair of eyes on your code every now and then

      Comment

      Working...