Welcome to the Treehouse Community
Looking to learn something new?
Oszkár FehérTreehouse Project Reviewer
I am stucked here a little bit, can someone help me out a little please?
i am not fully understand the question and i am not sure what i should do next
import random class Die: def __init__(self, sides=2): if sides < 2: raise ValueError("Can't have fewer than two sides") self.sides = sides self.value = random.randint(1, sides) def __int__(self): return self.value def __add__(self, other): return int(self) + other def __radd__(self, other): return self + other class D20(Die): def __init__(self): super().__init__(sides = 20)
from dice import D20 class Hand(list): def __init__(self, size=0, die_class=None, *args, **kwargs): if not die_class: raise ValueError("You must provide a die class") super().__init__() for _ in range(size): self.append(die_class()) def roll(self, size): super().__init__(size=size, die_class=D20, *args, **kwargs) @property def total(self): return sum(self)
Steven Parker216,175 Points
Here's a couple of hints:
- you don't need to override
__init__, just implement
- since you'll be returning a new instance, this might be a good place for a classmethod
Stephen ColeCourses Plus Student 13,133 Points
I had the same problems.
The self.sort() worked in the videos because we added all the magic methods needed to "do the math" required for sort to work.
Without them, the function didn't know what to do.
That was much harder than it needed to be.