Formatting and HTML Lab

This lab will give you practice using the format() function and the f-string and making HTML.

Part 1: Quotes

1.1. Write a string that uses single quotes.

[ ]:

1.2. Write a string that uses triple quotes.

[ ]:

1.3. Write a string that uses triple quotes and spans multiple lines.

[ ]:

1.4. Write an f-string.

[ ]:

1.5. Change the contents of the name variable to your name:

[ ]:
name = "Your name here"

Now copy this code into the cell below:

print("Hello {name}")
[ ]:

Now copy this code into the cell below:

print(f"Hello {name}")
[ ]:

Can you explain the difference in the output of the last two code cells?

Part 2: Formatting and f-Strings

Practice with the format function and f-strings.

2.1. Change this code to print your name:

name = "Your Name"
print(f'Hello my name is {name}')
[ ]:

2.2. Use the format() function to fill in your name.

Start with this code:

name = "Your Name"
print("Hello my nane is {}".format())
[ ]:

2.3. Use the format() function to fill in two blanks.

Start with this code:

print("My name is {} and my favorite color is {}".format())
[ ]:

2.4. Use the format() function to fill in the blank with a variable.

Start with this code:

name = "Your Name Here"
print("Hello my name is {}".format())
[ ]:

2.5. Use an f-string instead of format() to do the previous question.

[ ]:

2.6. Use the format() function to fill in two blanks with variables.

Start with this code:

name = "Your Name Here"
color = "Your Color Here"
print("My name is {} and my favorite color is {}".format())
[ ]:

2.7. Use an f-string instead of format() to do the previous question.

[ ]:

Part 3: Templates and Variables

3.1. Begin with the program below. Update it to print the values for a and b using the template.

template = "a = {}; b = {}"
a = 123
b = 95
[ ]:

3.2. Begin with the program below. Updatate it to print values for a and b as well as the product of the two numbers.

template = "The product of {} and {} is {}"
a = 123
b = 95
[ ]:

Part 4: HTML

The answers in this section should produce HTML output. Use the HTML and dispaly functions to do so.

4.1. Use HTML tags to make the following sentence bold.

I'm really serious.
[ ]:

4.2. Use HTML tags to make the following sentence italic.

Are you for real?
[ ]:

4.3. Use HTML tags to make the following sentence a level-1 heading.

My title is: title
[ ]:

4.4. Use HTML to make an unordered list of items like this:

  • Item 1

  • Item 2

  • Item 3

[ ]:

4.5. Use HTML to make a table like this:

Header 1

Header 2

Item 1

Item 2

Note: Your table will have a less pretty style, that’s okay.

[ ]: