Chapter 3 Activity Instructions

Chapter Three: Input and Output

Activity: Character Art

 

In this chapter, you learned how to nicely format strings using the print() and str.format() functions. You also learned how to gather information from the user with the input() function. In this project, you are going to make use of those skills to create a dynamic display of character artwork.

Reminder - Your Coding Platform

In the first chapter activity, you learned how to use our online Python engine to submit projects for grading. Or, you may have followed other instructions to code and test Python programs on your own computer and submit them to your teacher separately. Please review the first chapter activity instructions and your choice of a coding platform, if needed, for details on how to complete and submit this project.

Creating Character Artwork

Early computers were not able to display high-resolution, color images. Instead, creative users designed artwork using nothing more than the characters on your keyboard. Can you tell what this image represents?

+--------------------+
|        |>          |
|        |\          |
|        | \         |
|        |  \        |
|        |   \       |
|        |    \      |
|  \==============/  |
|   \____________/   |
|                    |
+--------------------+

In Python, you can create similar artwork by drawing one line at a time with print() statements. The following three statements would display the first three lines of our sample sailboat artwork.

print("+--------------------+")
print("|        |>          |")
print("|        |\          |")

Can you imagine how to create your own artwork, using just the characters on your keyboard?

Activity Requirements

In this activity, you are going to create a Python program that asks the user for an artist name. Your program will then print out an image of your own creation (or you can duplicate our sailboat). Near the bottom of the art frame, you should print the artist's name on a signature line.

Complete your program by following these steps:

  1. Start your Python code with a comment at the top showing your name.
  2. At the beginning of your program, ask for the artist's name using the input() function, and store the results in a variable called artist.
  3. Use multiple print() functions to display most of your creative artwork. Add as many print() lines as you need and experiment to get the image you want.
  4. Before you print a bottom line, build a signature string variable using the str.format() function. This variable should hold an output line containing the artist's signature. When building the signature line, your program should:
    • Ensure the artist name and surrounding spaces take up exactly enough characters (e.g. 20 characters) to fit your overall image. This means you need to set the width of the artist's name in the output.
    • Center the artist name within the horizontal space you have for the line.
    • Limit (truncate) the artist name to 10 characters when printing.
  5. You can meet signature line requirements by using the str.format() function and the widthtruncationand alignment options described in this chapter.

    Hint: If your overall image width is 22 characters, including a vertical bar character "|" on each edge for the frame, then you want your artist's name to be centered in a field that is 20 characters wide. Your format string for str.format() would start as "|{0:20}|" and then you would need to add the options for truncation to 10 characters and center alignment.

Activity Results

When you are done, run your code and verify the results. The example below shows our sailboat artwork with a signature line for the artist "Camille".

What is the artist name? Camille
+--------------------+
|        |>          |
|        |\          |
|        | \         |
|        |  \        |
|        |   \       |
|        |    \      |
|  \==============/  |
|   \____________/   |
|                    |
|       Camille       |
+--------------------+

Your own artwork may look very different; be creative! Be sure to test your program twice. The first time enter a name that is shorter than 10 characters. The second time enter a name that is longer than 10 characters, and make sure only the first 10 are printed on the signature line.

What is the artist name? Rumpelstiltskin
+--------------------+
|        |>          |
|        |\          |
|        | \         |
|        |  \        |
|        |   \       |
|        |    \      |
|  \==============/  |
|   \____________/   |
|                    |
|     Rumpelstil     |
+--------------------+

 

Activity Rubric

If your project is being automatically graded by our system, your grade will be calculated from 0 to 100 as follows:

PointsDescription
10Add comment with name as first line of code
10Declare and use artist variable
10Declare and use signature variable
10Use the input() function
10Use multiple print() functions
25Display correct signature with spacing when artist is less than or equal to 10 characters
25Display correct truncated, 10-character signature when artist is greater than 10 characters

 

End of Activity


Last modified: Wednesday, 8 May 2019, 8:12 AM