import webapp2 class MainPage(webapp2.RequestHandler): def get(self): # build the operation f = {'Calculate': lambda x, y: str(int(x) * int(y)), 'Clear': lambda x, y: "", } # get page parameters x = self.request.get('x') y = self.request.get('y') operator = self.request.get('operator') # calculate result = "" try: result = f[operator](x, y) except ValueError: result = "Error: Incorrect Number" except KeyError: pass calculate = ("") clear = ("") # buttons = "".join(["" for o in sorted(f.keys())]) self.response.out.write(''' Influence Reach Factor Calculator

The Influence Reach Factor Calculator

Cesar's Second Python Google App Engine Application


This is a simple experiment in web programming.
With grateful acknowledgment to Bukhantsov.org


Enter the number of friends you influence:
Enter the number of friends they each influence:
%s
''' % (calculate, )) self.response.out.write('''
Resulting IRF (Influence Reach Factor):
%s

copyright 2013, Cesar A. Brea ''' % (result, clear)) #def get(self): # # build a list of operations # f = {'+': lambda x, y: str(float(x) + float(y)), # '-': lambda x, y: str(float(x) - float(y)), # '*': lambda x, y: str(float(x) * float(y)), # '/': lambda x, y: str(float(x) / float(y)), # 'C': lambda x, y: "", # } # # get page parameters # x = self.request.get('x') # y = self.request.get('y') # operator = self.request.get('operator') # # calculate # result = "" # try: # result = f[operator](x, y) # except ValueError: # result = "Error: Incorrect Number" # except ZeroDivisionError: # result = "Error: Division by zero" # except KeyError: # pass # # build HTML response # buttons = "".join(["" for o in sorted(f.keys())]) # self.response.out.write(""" # #
#
#
# %s #
# # """ % (result, buttons)) app = webapp2.WSGIApplication([('/', MainPage)], debug=True)