Question: Modify Quotient Web Exercise and save it as a CGI script quotient.cgi in the same directory where you have localCGIServer.py and your output page template

Modify Quotient Web Exercise and save it as a CGI script quotient.cgi in the same directory where you have localCGIServer.py and your output page template for quotientWeb.py. Make quotient.cgi take its input from a browser, rather than the keyboard. This means merging all the standard CGI code from adder.cgi and the processInput function code from your quotientWeb.py. You can keep the same browser data names, x and y, as in adder.cgi, so the main method should not need changes from adder.cgi. Remember to test for syntax errors inside Idle, and to have the local web server running when you run the CGI script in your browser. Since we have not yet covered web forms, test your CGI script by entering test data into the URL in the browser, like by going to links http://localhost:8080/quotient.cgi?x=24&y=56 and http://localhost:8080/quotient.cgi?x=36&y=15. After trying these links, you can edit the numbers in the URL in the browser to see different results.

quotientWeb.py:

'''Prompt the user for two integers and display a web page with the sum.''' def processInput(numStr1, numStr2): # NEW '''Process input parameters and return the final page as a string.''' num1 = int(numStr1) # transform input to output data num2 = int(numStr2) q = num1//num2 r = num1%num2 return fileToStr('divisionTemplate.html').format(**locals())

def main(): # NEW numStr1 = input('Enter an integer: ') # obtain input numStr2 = input('Enter another integer: ') contents = processInput(numStr1, numStr2) # process input into a page browseLocal(contents) # display page def fileToStr(fileName): """Return a string containing the contents of the named file.""" fin = open(fileName); contents = fin.read(); fin.close() return contents def strToFile(text, filename): """Write a file with the given name and the given text.""" output = open(filename,"w") output.write(text) output.close() def browseLocal(webpageText, filename='tempBrowseLocal.html'): '''Start your webbrowser on a local file containing the text with given filename.''' import webbrowser, os.path strToFile(webpageText, filename) webbrowser.open("file:///" + os.path.abspath(filename)) #elaborated for Mac main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!