The task is to write a program called harry.py that when
executed will write a file called harry.html which will look like this (when viewed in a web browser): |
harry.html:
|
|
If we were to write the HTML code by hand for harry.html it would look like this: | <html><body> My name is <b>Mr. Brooks</b> </body></html> |
|
Here is one version of the program harry.py: Notice that there can be any number of f.write() statements -- they just keep writing strings out to the output file |
#! /usr/bin/python3 f = open("harry.html","w") f.write("<html><body>\nMy name is") f.write(" <b>Mr. Brooks</b>\n") f.write("</body></html>") f.close() |
|
Here is another way to do the same thing... Notice how much less work this is...(and will be more useful in the future)... |
#! /usr/bin/python3 t = ''' <html><body> My name is <b>Mr. Brooks</b> </body></html> ''' def main(): f = open("harry.html","w") f.write(t) f.close() main() |