#! /usr/bin/python3 # Demo of passing information from one page to another # using the What was the color of Washington's white horse?
Green        White      Transparent        Plaid

''' Question_2 = '''

When was the War of 1812?
Huh?          1813-1812         Never happened

What is the meaning of life?

''' Question_3 = '''

What is the meaning of life?
  42             sens de la vie       chocolate cake      97 in Intro-CS

''' Question_4 = '''

In an alternate universe, this class would be taught by?
Mr. Brooks, with backwards suspenders      Justin Beaver       a gopher       guacamole

''' Questions = [Question_1,Question_2,Question_3,Question_4] def main(): form = cgi.FieldStorage() # if there are no inputs, then we were called by the user for the # first time. Go to page 1 with score = 0 and no history if 'goto' not in form: goto_page = 'Page 1' score = 0 history = '' last_answer = '' else: goto_page = form.getvalue('goto') answer = form.getvalue('answer') if answer == 'right': last_answer = 'Your last answer was right' current_score = 1 else: last_answer = 'Your last answer was wrong' current_score = -1 # previous values were planted inside the values score = int(form.getvalue('score')) + current_score history = form.getvalue('history') # get the HTML from the next page filename = PagesDict[goto_page] html = open(filename,'r').read() # change stuff in it # show previous pages html = html.replace('',history) if history == '': history = goto_page else: history = history+','+goto_page # show last answer if last_answer != '': html = html.replace('', last_answer) # show score so far html = html.replace('',str(score)) # plant hidden score html = html.replace('',str(score)) # place history html = html.replace('',history) # random question which = random.randint(0,len(Questions)-1) html = html.replace('',Questions[which]) # That's it, print it print (html) main()