first the overall structure of the codeto handle the cgi input we import the cgi module the main body of the code is in main methodfollowing good programming practice after the definition of main come supporting functionseach one copied from the earlier local web page versionadditionweb py at the end is the newboilerplate cgi wrapper code for main(this is code that you can always just copy chose to put the initial print function herethat tells the server html is being produced that mean the main method only needs to construct and print the actual html code also keep the final try-except block that catches any execution errors in the program and generates possibly helpful trace information that you can see from your browser (how to write such error catching code in general is not covered in this introductory tutorialbut you can copy it in this situation!the main function has three sectionsas in the local web page versionread input (this time from the formnot the keyboard)process itand generate the html output reading inputthe first line of main is standard one (for you to copythat sets up an object called form that holds the cgi form data accompanying the web request sent by the browser you access the form data with statements like the next two that have the patternvariable form getfirstnameattrib default if there is form input field with name nameattribits value from the browser data is assigned to variable if no value is given in the browser' data for nameattribvariable is set equal to default instead in this way data associated with names given by the browser can be transferred to your python cgi programand if there is no such name in form feeding this cgi programthe program does not immediately bomb out in this program the values associated with the browser-supplied names'xand ' 'are extracted use slightly verbose python variable names that remind you that all values from the browser forms are strings the processinput function that is passed the input parameters from whatever sourceis exactly the same as in additionweb pyso we already know it worksoutput the page in cgi scriptthis is easier than with the local web pagesjust print it no need to save and separately display filethe server captures the "printedoutput this program can now serve as template for your own cgi scriptsthe only things you need to change are the lines in main(that get the input from web formusing the names from the input tags in the formand assigning the string values to python varibles in main call processinputwith all the data from the form that you need to pass as parameters to processinput the heading of the definition of processinput need to fit with the actual parameters passed by the call in main(furthermore the processinput part can be written and tested earlier with python program in the format of the web py programs that we have discussed while this is the only python codeyou still need to create an output web page templateand refer to it as the parameter of filetostr againif you tested your logic using an earlier web py programjust use the same output web templatea stripped down skeletonto start cgi program fromwith comments about needed changes is in skeletonfor cgi if you do not want to start your code by modifying an existing example cgi programthen you might start by copying skeletonfor cgi idle and cgi files you can always start idle way that you have beforelike on an existing py file then deal with editing cgi files from inside idle cgi dynamic web pages