Lab: Formatting and HTML#

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

Part 1: Quotes#

1. Single Quotes#

Write a string that uses single quotes.

[ ]:

2. Triple Quotes#

Write a string that uses triple quotes.

[ ]:

3. Multi Line String#

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

[ ]:

4. f-String#

Write an f-string.

[ ]:

5. Assign Name#

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.

1. Print Your Name#

Change this code to print your name:

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

2. Format#

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

Start with this code:

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

3. Format Two Blanks#

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

Start with this code:

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

4. Variable Blank#

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())
[ ]:

5. F-String Instead#

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

[ ]:

6. More Blanks#

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())
[ ]:

7. F-String Instead#

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

[ ]:

Part 3: Templates and Variables#

1. Use a Template#

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
[ ]:

2. More Templates#

Begin with the program below. Update 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 display functions to do so.

1. Bold#

Use HTML tags to make the following sentence bold.

I'm really serious.
[ ]:

2. Italic#

Use HTML tags to make the following sentence italic.

Are you for real?
[ ]:

3. Heading#

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

My title is: title
[ ]:

4. Unordered List#

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

  • Item 1

  • Item 2

  • Item 3

[ ]:

5. Table#

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.

[ ]: