Results 1 to 3 of 3

Thread: Learning Python, having a bit of trouble

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Apr 2007

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

    #! /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!"
    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.
    year = int(y)
    if year == 0:
            print "Year 0 does not exist!"
    print year
    if (year % 400) == 0:
            print " is "
    elif (year % 100) == 0:
            print " is not "
    elif (year % 4) == 0:
            print " is "
            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?


  2. #2
    Administrator AndrewT's Avatar
    Join Date
    Mar 2004
    Tulsa, OK


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

  3. #3
    Junior Member
    Join Date
    Apr 2007


    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts