2.2k views
5 votes
Write a program that asks the user (you) for the following information:

Enter his/her name
Enter degree major
Enter your future career and a brief description of the career
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:

main
Get the information from the user
Create the html file for writing
Write the html by calling the write_html function and sending the information to write
Close the file
write_html
write the html tag
write the head element by calling the write_head function and sending the name of the html file created above
write the body by calling a write_body function and sending all of the information to write the body)
write the closing html tag
write_head
write the opening head tag
write the opening title tag , the name of your web page that will show in the browser tab, and closing title tag
write the closing head tag
write_body
Body tags are shown below. Make sure that you replace the red placeholder text with the variable used to store the user input.

1 Answer

4 votes

Below is the program for the above information.

Python

def main():

# Get the information from the user

name = input("Enter your name: ")

degree_major = input("Enter your degree major: ")

future_career = input("Enter your future career: ")

career_description = input("Enter a brief description of your future career: ")

# Create the HTML file for writing

with open('user_information.html', 'w') as html_file:

# Write the HTML content

write_html(html_file, name, degree_major, future_career, career_description)

def write_html(html_file, name, degree_major, future_career, career_description):

# Write the HTML tag

html_file.write("<!DOCTYPE html>")

# Write the head element

write_head(html_file, "User Information")

# Write the body

write_body(html_file, name, degree_major, future_career, career_description)

# Write the closing HTML tag

html_file.write("</html>")

def write_head(html_file, title):

# Write the opening head tag

html_file.write("<head>")

# Write the opening title tag

html_file.write("<title>" + title + "</title>")

# Write the closing head tag

html_file.write("</head>")

def write_body(html_file, name, degree_major, future_career, career_description):

# Write the body tags

html_file.write("<body>")

html_file.write("<h1>User Information</h1>")

html_file.write("<p>Name: " + name + "</p>")

html_file.write("<p>Degree Major: " + degree_major + "</p>")

html_file.write("<p>Future Career: " + future_career + "</p>")

html_file.write("<p>Career Description: " + career_description + "</p>")

html_file.write("</body>")

if __name__ == "__main__":

main()

So, the above program is one that defines three functions (write_html, write_head, and write_body) to handle writing different parts of the HTML document.

Hence, The main function takes user input and creates an HTML file by calling these functions. The resulting HTML file (user_page.html) will contain the information entered by the user.

User Sunny Agarwal
by
8.0k points