University of Arizona, Department of Computer Science

CSc 120: Street

The primary purpose of this problem is to gain more experience with recursion.

Restrictions

  1. For the long problems, your code should follow the style guidelines for the class.
  2. You may not use concepts and/or short-hand syntax not yet covered in class. The restrictions include the following:

Expected Behavior

Write a Python program in, street.py, that prompts the user for a one-line specification of a city street and then prints a simple ASCII rendering of it. The user should be prompted as follows:

input("Street: ")
The user responds with a specification that has some number of buildings, parks, and empty lots. As an example, the input line
p:19,* b:5,7,x e:7,__~
is rendered as this:
+-------------------------------+
|                               |
|                   xxxxx       |
|                   xxxxx       |
|         *         xxxxx       |
|        ***        xxxxx       |
|       *****       xxxxx       |
|         |         xxxxx       |
|         |         xxxxx  ~  ~ |
+-------------------------------+

Input format

The input will be a single line that contains one or more whitespace-separated specifications for buildings, parks, and/or empty lots that appear along the street.

Here is a more complex street:

b:3,10,a e:10,+- p:13,* b:7,15,x b:17,4,% b:10,8,y e:5,_ b:1,3,$ p:13,^ b:10,3,# e:9,__.
and its rendering:
+--------------------------------------------------------------------------------------------------+
|                                                                                                  |
|                          xxxxxxx                                                                 |
|                          xxxxxxx                                                                 |
|                          xxxxxxx                                                                 |
|                          xxxxxxx                                                                 |
|                          xxxxxxx                                                                 |
|aaa                       xxxxxxx                                                                 |
|aaa                       xxxxxxx                                                                 |
|aaa                       xxxxxxx                 yyyyyyyyyy                                      |
|aaa                       xxxxxxx                 yyyyyyyyyy                                      |
|aaa                       xxxxxxx                 yyyyyyyyyy                                      |
|aaa                *      xxxxxxx                 yyyyyyyyyy            ^                         |
|aaa               ***     xxxxxxx%%%%%%%%%%%%%%%%%yyyyyyyyyy           ^^^                        |
|aaa              *****    xxxxxxx%%%%%%%%%%%%%%%%%yyyyyyyyyy     $    ^^^^^    ##########         |
|aaa                |      xxxxxxx%%%%%%%%%%%%%%%%%yyyyyyyyyy     $      |      ##########         |
|aaa+-+-+-+-+-      |      xxxxxxx%%%%%%%%%%%%%%%%%yyyyyyyyyy     $      |      ##########  .  .  .|
+--------------------------------------------------------------------------------------------------+

Output format

Along with the specifications above, note these points:

Programming Requirements

First, read the design approach discussed in this link: Street Class Design.

You must implement the three classes that represent the building, park, and empty lot elements of a street. Specifically, write the following three classes:

For each class, implement an at_height method for the class that returns a string that is the text for that element at the specified height. Otherwise, you may write any additional methods for your classes that are needed to implement the full functionality of the program.

An essential requirement of this problem is that you may not use any for or while statements or list comprehensions in your solution. Use recursion in place of looping, as you've seen done in lecture and have done yourself when solving the short problems and ICAs on recursion. In addition, don't use any built-in Python functions that implicitly examine every element of a list, such as sum(), index(), join(), replace() and max(). (However you can use max(a,b) where a and b are integers.)

Note: You may use split() on the line of input from the user and the multiple concatenation operator *.

More examples

Some additional examples of the behavior of this program are given Street-Input-Output Examples.

Errors

No error checking is required for this program.