#-------------------------------------------------------------------------------- # Program to illustrate the dynamic creation of HTML Web pages. # Also, in this program global variables are introduced. The global variable # MyFile (a file handle) is shared between Main and Write without going through # the parameter lists. Function Write is designed so that the file handle need # not be explicitly part of every file write, and so that the terminating line # break (the \n) is never forgotten. Note that the indentation for the HTML # document is NOT required (as it is in Python) but is there to aid in the # debugging process. # # Writing programs to create documents in other languages (even other # programming languages) is fairly common today. Python scripts are often used # to respond to Web requests (on-line ordering) by generating a response page # dynamically. In this case, entering a large number in the request for the # number of roots may mean that thousands of lines of HTML are written to the # file; a task all but impossible by hand. # # (C) March 31, 2017 -- Dr. William T. Verts #-------------------------------------------------------------------------------- def Write (S): global MyFile MyFile.write(S + "\n") return def Main(): global MyFile Filename = pickAFolder() + "MyWebPage.html" Title = requestString("Enter the Title") MyColor = requestString("Enter a Color Name") Roots = requestInteger("Enter number of Square Roots") MyFile = open(Filename, "w") Write ("") Write ("
") Write ("" + str(I) + " | ") Write ("" + str(sqrt(I)) + " | ") Write ("