Totem.py and write functions in that module. The code
you write must conform to the totem standards below. When you create
the module, let Eclipse create the if __name__ ==
'__main__' boilerplate for you by selecting the option
"Module: Main" when you create the new Python Module from the popup.
TIP: Write a few functions at a time and run your program to see if they work. Then add more functions and test them. Your program will be easier to debug if you do this! If you do have errors, always fix the first error in the file first. The others might go away when you do.
For example function names can be chin_cleft,
hair_bald, mouth_open, or
mouth_v1. You cannot use a name
like mouth or earClogged because these don't
conform to the naming specification. The "meaningful"
description can be anything.
hair_part below:
17*k + (k-1) where k is the number
of lines represented by the string. A one-line string will be exactly
17-characters, a two-line string will be two lines of 17 separated by
one new line character so it's length will be 35 = 17*2 +
(2-1) characters
Some of the characters in each line can be spaces, but each must have length seventeen as a string (again, multi-line strings are fine).
totem and another 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". You can also write functions to create
individual heads that print the values returned by the so-called
parts functions.
The function, randompole, should create different
poles each time it is called based on using the Python random
module and using if/elif statements. Bowties should be randomly
added to the head or not added. (so not all heads may have a bowtie on).
totem function as well, not
just the randompole function.
hair_parted that conforms to the totem standards.
def hair_parted():
return " "*3 + r"\\\\\\\\\\\//////"
Note that in this example, 3 spaces are concatenated to 17 characters in
a raw string because " "*3 is a three-space string.
There is one exception to using raw strings. You cannot end the string with
a single backslash (or actually an odd number of backslashes).
If you want to end the string with a single backslash (or odd number of backslashes)
then add a blank at the end and it is ok to be of length 17+1 blank, so
length 18 for that string. Here is an example. Use the second a2 line.
def hair_pointy():
a1 = r"12345678901234567"
a2 = r"/\/\/\_/\/\/\/\/\" # THIS GIVES A SYNTAX ERROR because it ends
# in a single backslash
a2 = r"/\/\/\_/\/\/\/\/\ " # Instead use this line which has an 18th
# character that is a blank after the backslash
a3 = r"| |"
return a2 + "\n" + a3
random library
and then call the function random.randint(low,high).
When you use an import statement, it is best to put them near the top of the file before any defs or other code so that any of your code can use the imports.
The example below returns three different strings with equal probability.
We haven't covered if/elif/else statements yet but you can read ahead in the CompSci 101 textbook the first four sections of the Selection Chapter which you need to complete a reading quiz for by the time this assignment is due.
Totem should print three heads and might look like (assuming these are functions you wrote):
def totem():
# head 1
print hat_tall()
print hair_plain()
print eyes_slanted()
print nose_big()
print mouth_small()
print chin_plain()
# heads 2 and 3 follow and are not shown
if __name__ == '__main__':
# main function to print a totem pole
# with three heads followed by a random totem pole
print "My totem pole"
totem() # just call a printing function
print
print
print "My random totem pole"
randompole()
OR ANOTHER WAY. You might have created functions for each head called head1(), head2() and head3(). Then you might have:
def head1():
print hat_tall()
print hair_plain()
print eyes_slanted()
print nose_big()
print mouth_small()
print chin_plain()
def totem():
head1()
[rest of code not shown]
if __name__ == '__main__':
# main function to print a totem pole
# with three heads followed by a random totem pole
print "My totem pole"
totem() # just call a printing function
print
print
print "My random totem pole"
randompole()