#!/Library/Frameworks/Python.framework/Versions/Current/bin/python # L-21 MCS 275 Mon 1 Mar 2010 : web_gcd.py import cgi form = cgi.FieldStorage() print "Content-Type: text/plain\n" try: x = form['A'].value print "your first number is " + x except KeyError: print "please enter a first number" try: y = form['B'].value print "your second number is " + y except KeyError: print "please enter a second number" def gcd(a,b): # the code from Lecture 1 ! r = a % b if r == 0: return b else: return gcd(b,r) ix = int(x) iy = int(y) print "gcd(%d,%d) = %d" % (ix,iy,gcd(ix,iy))