#!/usr/local/bin/python ####################################################### # runs on the server, reads form input, prints html; # url=http://server-name/root-dir/Basics/test3.cgi ####################################################### import cgi import string import sys sys.stderr = sys.stdout form = cgi.FieldStorage() # parse form data print "Content-type: text/html" # plus blank line html = """ test3.cgi

Greetings


%s


""" options = ["Python", "Perl", "Ruby", "Tcl", "JavaScript", "Visual Basic", "Java", "C++", "C", "Lisp", "Delphi"] criteria = ["ease of learning", "ease of use", "speed of program execution", "quality of available tools", "popularity", "power & expressiveness", "cross platform?", "cost"] rankings = {"ease of learning" : form['easelearning'].value, "ease of use" : form['easeuse'].value, "speed" : form['speed'].value, "tools" : form['tools'].value, "pop" : form['pop'].value, "power" : form['power'].value, "cross" : form['cross'].value, "cost" : form['cost'].value} score = {("Python", "ease of learning"):100, ("Python", "ease of use"):100, ("Python", "speed of program execution"):10, ("Python", "quality of available tools"):70, ("Python", "popularity"):50, ("Python", "power & expressiveness"):100, ("Python", "cross platform?"):100, ("Python", "cost"):100, ("Perl", "ease of learning"):50, ("Perl", "ease of use"):90, ("Perl", "speed of program execution"):30, ("Perl", "quality of available tools"):50, ("Perl", "popularity"):75, ("Perl", "power & expressiveness"):100, ("Perl", "cross platform?"):100, ("Perl", "cost"):100, ("Ruby", "ease of learning"):50, ("Ruby", "ease of use"):100, ("Ruby", "speed of program execution"):20, ("Ruby", "quality of available tools"):20, ("Ruby", "popularity"):10, ("Ruby", "power & expressiveness"):100, ("Ruby", "cross platform?"):80, ("Ruby", "cost"):100, ("Tcl", "ease of learning"):100, ("Tcl", "ease of use"):100, ("Tcl", "speed of program execution"):10, ("Tcl", "quality of available tools"):50, ("Tcl", "popularity"):40, ("Tcl", "power & expressiveness"):10, ("Tcl", "cross platform?"):100, ("Tcl", "cost"):100, ("JavaScript", "ease of learning"):70, ("JavaScript", "ease of use"):75, ("JavaScript", "speed of program execution"):10, ("JavaScript", "quality of available tools"):50, ("JavaScript", "popularity"):100, ("JavaScript", "power & expressiveness"):40, ("JavaScript", "cross platform?"):50, ("JavaScript", "cost"):100, ("Visual Basic", "ease of learning"):50, ("Visual Basic", "ease of use"):100, ("Visual Basic", "speed of program execution"):20, ("Visual Basic", "quality of available tools"):100, ("Visual Basic", "popularity"):100, ("Visual Basic", "power & expressiveness"):50, ("Visual Basic", "cross platform?"):1, ("Visual Basic", "cost"):1, ("Java", "ease of learning"):15, ("Java", "ease of use"):50, ("Java", "speed of program execution"):50, ("Java", "quality of available tools"):100, ("Java", "popularity"):100, ("Java", "power & expressiveness"):100, ("Java", "cross platform?"):100, ("Java", "cost"):100, ("C++", "ease of learning"):10, ("C++", "ease of use"):25, ("C++", "speed of program execution"):90, ("C++", "quality of available tools"):100, ("C++", "popularity"):100, ("C++", "power & expressiveness"):100, ("C++", "cross platform?"):100, ("C++", "cost"):100, ("C", "ease of learning"):15, ("C", "ease of use"):10, ("C", "speed of program execution"):100, ("C", "quality of available tools"):100, ("C", "popularity"):100, ("C", "power & expressiveness"):100, ("C", "cross platform?"):110, ("C", "cost"):100, ("Lisp", "ease of learning"):20, ("Lisp", "ease of use"):30, ("Lisp", "speed of program execution"):70, ("Lisp", "quality of available tools"):50, ("Lisp", "popularity"):25, ("Lisp", "power & expressiveness"):110, ("Lisp", "cross platform?"):80, ("Lisp", "cost"):90, ("Delphi", "ease of learning"):50, ("Delphi", "ease of use"):110, ("Delphi", "speed of program execution"):85, ("Delphi", "quality of available tools"):100, ("Delphi", "popularity"):30, ("Delphi", "power & expressiveness"):100, ("Delphi", "cross platform?"):80, ("Delphi", "cost"):10} result = {} for o in options: value = 0 for c in criteria: value = value + rankings[c] * score[o, c] result[o] = value results = result.items() # A list of tuples (key, value) results.sort(lambda x, y: -cmp(x[1], y[1])) # Sort the list using the reverse of the # "value" of the entry, so that higher # values come first print html % ("Hello, %s." % form['easeuse'].value) print html % form['easeuse'].value