import random class MSDie: """ Multi-sided die Instance Variables: current_value num_sides """ def __init__(self, num_sides: int) -> None: """Create an instance and genearte a random value Arg: num_sides (int): number of sides on dice Return: None """ self.__num_sides = num_sides self.__current_value = self.roll() @property def side(self) -> int: return self.__num_sides @side.setter def side(self, s: int) -> None: self.__num_sides = s @side.deleter def side(self) -> None: del self.__num_sides @property def num(self) -> int: return self.__current_value @num.setter def num(self, n: int) -> None: self.__current_value = n @num.deleter def num(self) -> None: del self.__current_value def roll(self) -> int: """Create a random number Return: int: current dice value """ self.__current_value = random.randrange(1,self.__num_sides+1) return self.__current_value def __str__(self) -> str: return 'Dice: '+str(self.__current_value) def __repr__(self) -> str: return "MSDie({}) : {}".format(self.__num_sides, self.__current_value) def __eq__(self, other: 'MSDie') -> bool: if self.__current_value == other.__current_value: return True else: return False def __lt__(self, other: 'MSDie') -> bool: if self.__current_value < other.__current_value: return True else: return False
my_die = MSDie(6) print(my_die.side, my_die.num) d1 = MSDie(6) d2 = MSDie(6) print(d1, d2) print(d1 == d2) print(d1 < d2) print(d1 > d2)