Your mission is to define a Tree class so that you can:
>>> family = Tree("Doug") >>> family.depth() 1 >>> family.mother = Tree("Norma") >>> family.depth() 2 >>> family.father = Tree("Scotty") >>> family.depth() 2 >>> family.father.mother = Tree("Mildred") >>> family.depth() 3
Depth will print out the maximum generations of the tree (ie, the max depth of the tree).
Next, can you make a method to add the mother and father:
>>> family.mother.addMother("Awilda") >>> family.mother.addFather("Norman")
Next, add a method to figure out how many ancestors you have in the tree (don't count you):
>>> family.ancestors() 5 >>> family.mother.ancestors() 2 >>> family.mother.mother.ancestors() 0
Finally, make your tree so you can print it out. Here is a simple print out:
>>> tree.print() --- Doug ------ Scotty --------- Mildred ------ Norma --------- Norman --------- AwildaThis one looks better:
>>> tree.print() Doug Scotty Norma Mildred Awilda Normanor even:
>>> tree.print() Doug +----------|----------+ | | Scotty Norma +-----|-----+ +-----|-----+ | | | | Mildred Awilda Norman
Can you make your family tree print out nicely? HINT: You should know what the depth of the tree is before starting to print. Make your print code work with any tree---don't make it work just for yours. You may find the section in the text on String Formatting useful.
You may work in teams of two for this assignment. Each team should turn in: