Compsci 6/101, Spring 2011, Totem Howto

Getting Started

Create a new Pydev project. You can call the project by any name, but we suggest compsci06-totem to help you identify the project in your workspace. You must create a Python module named Totem.py and write functions in that module. The code you write must conform to the totem standards below.

Totem Standards

  1. Each function that you write to draw a part of a totem should have one of the following strings as the first part of the function name. Every function you write should begin with one of these strings. Please do not write helper functions that these call, even if such functions would make it simpler for you to write these functions. Please do not write nested/inner functions either.

  2. Each function must return a string that is fifteen characters "wide". The string can be a mult-line string, where each line is fifteen characters in length. e.g., you can write the function hair_part below: def hair_part(): a1 = r"123456789012345" a2 = r"|||||||||||||||" a3 = r"\\\\\\|||||||||" return a2 + "\n" + a3 To be more precise, the string returned by each of these functions must have length 15*k + (k-1) where k is the number of lines represented by the string. A one-line string will be exactly 15-characters, a two-line string will be two lines of 15 separated by one new line character so it's length will be 31 = 15*2 + (2-1) characters

    Some of the characters in each line can be spaces, but each must have length fifteen as a string (again, multi-line strings are fine).

  3. Each of the functions whose name is based on one of the parts above must return a string. You'll write two functions that don't return strings, but instead print the strings that make up a totem-pole. One of these functions should be named totem and the other should be named randompole. The first will print the same totem-pole each time it is called. The totem-pole must consist of at least three different "heads".

    The second function, randompole, should create different poles each time it is called based on using the Python random module.

  4. This means all face/head parts should be fifteen characters wide. You can have parts of a totem-head that are fewer than fifteen characters wide as in the faces shown below, but when each line is considered with spaces, it will be fifteen characters wide.

    The main idea in these standards is that someone's eye_ball function and a different person's chin_chin function could be used together. If your faces are lined up, your code is fine. If your face parts can be used with someone else's parts, that's even better. So try to adhere to the standards, but that's not the principle part of this assignment.

    123456789012345
    
     ||||||||||||           
     |          |           
    _|          |_
    \  ()    ()  /       
     \_        _/        
       |  oo  |           
       |      |           
       |  --  |
       |      | 
       +------+           
    
    123456789012345
     ~~~~~~~~~~~~~	  
     \ ---   --- /	  
     _\ O     O /_	  
    (_           _) 
      ]   ( )   [ 
      |         |	  
      \         /	  
       \\\\\////          
        \\\////		  
         \\///		  
          \//             
    
    
  5. According to the instructions in the assignment, you must have one function named totem that results in generating three totem heads.

  6. You should use the main Python idiom we've seen to run both totem and randompole when the program is run, e.g., from Eclipse: if __name__ == "__main__": totem() randompole()

Creating and Printing Strings

All strings you return and print should use what Python calls "raw" Strings. Strings preceded by a letter r before the double quote that begins the string will result in the string being printed without the need for any escape backslashes. For example: print "\" generates an error in Python because the second quote " has been escaped, however print "\\" will print one backslash. To avoid the need to line things up when backslashes are escaped, use raw strings as shown in the example below. print r"| \\// |" print r"| --- |" the letter 'r' before the string means that whatever follows the 'r' will be printed exactly as shown, no characters will be interpreted as escape characters or in any other way, they'll simply be printed. You can combine raw strings with other characters by concatenting them in one line as shown below for the function hairParted that conforms to the totem standards.
    def hairParted():
        return " "*5 + r"\\\\\\\\//"
Note that 5 spaces are concatenated to 10 characters in a raw string.