< Back

Lab 5: Text Processing

One of the most common forms of "media" in our daily lives is text. Not only is your textbook made of text, but a majority of social media sites rely fully on text. In addition, you can get books digitally on tablets and e-readers as well. One very common thing that happens with text is transformation. On Facebook, your wall is customized based off what you and your friends have entered into the webpage. Today, we will begin exploring how programs can be written to modify text in this fashion.


Story

In a file called Story.py, write a function called tell_story that prints a story when executed. Your story must be at least 5 lines long, and must include 2 different characters, 2 different actions, and two objects that the two characters are interacting with. The characters, actions, and objects should be specified as a parameter to the tell_story function.

Example

====== Loading Program ======
>>> tell_story("Link", "Gannon", "block", "stab", "master sword", "triforce")
The sky turned a pale blue color as Link reached the top of the staircase.
As Link approached the pedestal holding the master sword, Gannon suddently appeared.
Link lunged for the master sword, but Gannon was able to block the attempt.
Using the power imbuned in him by the triforce, Link summoned the courage to grab the master sword.
Link went to stab Gannon with the master sword, but was unsuccessful in his attempt.
As it turns out, this was only the beginning of their epic encounter.

Hint


Pyramid

In a file called fancy_pyramid.py, write a function pyramid(char, lines) that prints a series of characters, each on their own line. In this function, char is the character that you want to print in the pyramid, and lines is the number of lines to print. Each line should have one fewer asterisk than the previous line. This is different from the one in the book, which increases the number of characters to each line by a factor of 2. To allow this pyramid to line up, you need to add additonal spaces to the inside of the pyramid. After each character, add a space to the output as well.

Example

====== Loading Program ======
>>> pyramid("*", 10)
 * * * * * * * * * *
  * * * * * * * * *
   * * * * * * * *
    * * * * * * *
     * * * * * *
      * * * * *
       * * * *
        * * *
         * *
          *

Hint