Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def triangle(a, b, c):
- if a < b + c and b < a + c and c < a + b and 0 not in [a, b, c]:
- if a == b and b == c:
- return 'equilateral'
- elif a == b or b == c or a == c:
- return 'isosceles'
- else:
- return 'scalene'
- else:
- raise TriangleError()
- def score(dice):
- # You need to write this method
- dice_map = {}
- for p in xrange(1, 7):
- dice_map[p] = dice.count(p)
- total_points = 0
- def mult_helper(index, mult):
- mult_ = dice_map[index] / 3
- dice_map[index] -= 3 * mult_
- return mult * mult_
- # * A set of three ones is 1000 points
- total_points += mult_helper(1, 1000)
- # * A set of three numbers (other than ones) is worth 100 times the
- # number. (e.g. three fives is 500 points).
- for key in dice_map:
- total_points += mult_helper(key, key * 100)
- # * A one (that is not part of a set of three) is worth 100 points.
- total_points += dice_map[1] * 100
- # * A five (that is not part of a set of three) is worth 50 points.
- total_points += dice_map[5] * 50
- return total_points
- class Proxy(object):
- __internals__ = "_messages", "_obj"
- def __init__(self, target_object):
- # WRITE CODE HERE
- #initialize '_obj' attribute last. Trust me on this!
- self._obj = target_object
- # to save messages
- self._messages = []
- def __setattr__(self, attr, value):
- if attr not in self.__internals__:
- self._messages.append(attr + "=")
- return setattr(self._obj, attr, value)
- else:
- super(Proxy, self).__setattr__(attr, value)
- def __getattr__(self, attr):
- if attr not in self.__internals__:
- self._messages.append(attr)
- if hasattr(self._obj, attr):
- return getattr(self._obj, attr)
- else:
- raise AttributeError(attr)
- else:
- return super(Proxy, self).__getattr__(attr)
- def messages(self):
- return self._messages
- def was_called(self, name):
- return name in self._messages
- def number_of_times_called(self, name):
- return self._messages.count(name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement