# 2015-06-10 # Fancier version of the Die class import random class Die(): count = 0 # class variable def __init__(self, sides=6, startValue=1): self.sides = sides self.startValue = startValue self.faceValue = startValue # instance variable Die.count += 1 # update the class counter def __str__(self): return "face value: " + str(self.faceValue) def __int__(self): return self.faceValue def __eq__(self, otherDie): return int(self) == int(otherDie) def __add__(self, otherDie): return int(self) + int(otherDie) def roll(self): self.faceValue = random.randint(self.startValue, self.startValue+self.sides-1)