Lecture 10:  Loops

Activity:



More ASCII art!!  We have seen loops in the past two lectures.  This activity gives you the opportunity to write functions to create a picture of a tree like the one shown below.

     *
    ***
     *
    ***
   *****
     *
    ***
   *****
  *******
     |
-----+-----

Note that the tree consists of drawing spaces, stars, a vertical line, a plus sign, and minus signs.  Write a function called print_tree that takes as a parameter the size of the tree.  The size is the number of tiers (or triangles) that make up the tree.  In the above picture, there are 3 tiers.  You may assume that the size of the tree is greater than or equal to 1.

Hints:
1.  Before diving into the code, be sure to design your algorithm -- think about how many spaces and stars are required to print one tier of the tree.
2.  Think about writing a separate function called print_tier that simply prints a single tier of the tree given the number of rows and the center position for the tier.
3.  Use the entire design process -- problem specification, algorithm, function design, implementation, and testing.