Question: ;Python: * Save additionWeb.py or skeletonForWeb.py as quotientWeb.py. Modify it to display the results of a division problem in a web page. As in the

;Python:

* Save additionWeb.py or skeletonForWeb.py as quotientWeb.py. Modify it to display the results of a division problem in a web page. As in the exercises in Chapter 1, display a full sentence labeling both the integer quotient and the remainder. You can take your calculations from Quotient String Return Exercise. You should only need to make Python changes to the processInput and main functions. You will also need the HTML for the page displayed. Make a web page template file called quotientTemplate.html and read it into your program.

additionWeb.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) total = num1+num2 return fileToStr('additionTemplate.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!