In: Computer Science
Generate a Personal Web Page:
Write a program that asks the user (you) for the following information:
Once the user has entered the requested input, the program should create an HTML file, write the html file utilizing the tags below, and display the user entered text in the placeholder of the red text for a simple Web page.
Your program should include the following functions:
, the name of your web page that will show in the browser tab, and closing title tag
This is what I have but it is throwing errors:
def main():
print('Enter the following information to create your')
print('your personal web page')
name = input('Enter your full name: ')
major = input('Enter your degree major: ')
career = input('Describe your ideal future career: ')
f = open('profile.html', 'w')
write_html()
f.close()
def write_html():
html = '<html>\n' +\
write_head(f) +\
write_body() +\
'</html>\n'
def write_head():
head = '<head>\n' +\
print('My Personal Web Page') +\
'</head>\n'
def write_body():
body = '<body>\n' +\
'<h1>' + name + '</h1>\n' +\
'<hr />\n' +\
'<h2>' + major + '</h2>\n' +\
'<hr />\n' +\
'<hr />' + career + '</hr>\n' +\
'</body>'
main()
'''
Python version : 3.6
Python program to generate a Personal Web Page
'''
# main function to input the name, major and career from user and call write_html to create the html file
def main():
# input the details from user
print('Enter the following information to create your')
print('your personal web page')
name = input('Enter your full name: ')
major = input('Enter your degree major: ')
career = input('Describe your ideal future career: ')
f = open('profile.html', 'w') # open the file in write mode
write_html(f, name, major, career) # call write_html to populate the html file
f.close() # close the file
# function to write html, head and body tags to html file
def write_html(f, name, major, career):
f.write( '<html>\n') # output the opening html tag
write_head(f) # call function to write the head part
write_body(f, name, major, career) # call function to write the body part
f.write('</html>') # output the closing html tag
# function to write the head part of the html
def write_head(f):
f.write('<head>\n') # output the opening head tag
f.write('<title>\n') # output the opening title tag
f.write('My Personal Web Page\n') # output the title of the page
f.write('</title>\n') # output the closing title tag
f.write('</head>\n') # output the closing head tag
# function to write the body part of the html
def write_body(f, name, major, career):
f.write('<body>\n') # output the opening body tag
# output the name, major and career in body
f.write('<h1>'+name+'</h1>\n<hr/>\n')
f.write('<h2>'+major+'</h2>\n<hr/>\n')
f.write('<hr/>'+career+'<hr/>\n')
f.write('</body>\n') # output the closing body tag
#call the main function
main()
#end of program
Code Screenshot:

Output:

