# Program to write a HTML page to display shades of red, green, and blue. import webbrowser, os.path def strToFile(text, filename): """Write a file with the given name and the given text.""" output = open(filename,"w") output.write(text) output.close() #create the contents string contents = ''' Colors

Colors

''' for i in range(8): r = str(i*32 + 31) contents += "

Red "+r+", Green 0, Blue 0

\n" for i in range(8): g = str(i*32 + 31) contents += "

Red 0, Green "+g+", Blue 0

\n" for i in range(8): b = str(i*32 + 31) contents += "

Red 0, Green 0, Blue "+b+"

\n" contents += ''' ''' #the filename for the HTML file to be created filename = "colors.html" #write the HTML contents to a file strToFile(contents, filename) #open the HTML file in the default browser webbrowser.open("file:///" + os.path.abspath(filename))