#!/usr/bin/python2.2 -u import sys import cgitb; cgitb.enable() import MySQLdb from random import choice, shuffle sys.stderr = sys.stdout print "Content-Type: text/html\n\n" conn = MySQLdb.connect(user="xxx",passwd="xxx") # actual values concealed conn.select_db("usa") curr = conn.cursor() numrecs = curr.execute("select statename, postal, capital from states;") recs = curr.fetchall() conn.close() cities = [] states = [] for record in recs: statename, postal, capital = record cities.append(capital) states.append((statename, postal)) print "" print "
| '
randstate = choice(states)
print " What is the capital of %s? (%s) " % randstate print """ " print "" print " " print "Return to geoquiz home page" print " |