Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def weight(self):
  2. """The total weight of the mobile."""
  3. #proceed left
  4. def count_this(branch):
  5. if type(branch.contents) == type(Weight):
  6. return branch.contents.weight
  7. if type(branch.left.contents) != type(Weight):
  8. return count_this(branch.left)
  9. else type(branch.right.contents) != type(Weight):
  10. return count_this(branch.right)
  11.  
  12.  
  13. return count_this(self.branch.left) + count_this(self.branch.right)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement