Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBob Prestridge
8,400 PointsStuck on this task: not sure where I'm going wrong
Here's the challenge:
We're playing a popular board game about snatching up real estate in Atlantic City. I need you to finish out the Capitalism.
I don't understand where I'm going wrong here. Any help is greatly appreciated.
Thanks!
from dice import D6
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())
self.sort()
def _by_value(self, value):
dice = []
for die in self:
if die == value:
dice.append(die)
return dice
class CapitalismHand(Hand):
def init(self, *args, **kwargs):
super().init(size=2, die_class=D6, *args, **kwargs)
@property
def ones(self):
return self._by_value(1)
@property
def twos(self):
return self._by_value(2)
@property
def threes(self):
return self._by_value(3)
@property
def fours(self):
return self._by_value(4)
@property
def fives(self):
return self._by_value(5)
@property
def sixes(self):
return self._by_value(6)
@property
def _sets(self):
return {
1: len(self.ones),
2: len(self.twos),
3: len(self.threes),
4: len(self.fours),
5: len(self.fives),
6: len(self.sixes)
}
3 Answers
rshap
12,433 PointsI'm not sure what is the error that the site gives you, but you need to put the dunder around init():
class CapitalismHand(Hand):
def init(self, *args, **kwargs):
super().__init__(size=2, die_class=D6, *args, **kwargs)
Iain Watson
3,031 PointsI set size=2 and die_class=6 in the init of the parent Hand class. That worked for me. Not sure why your approach doesn't work. Adding the doubles property in the parent class also worked for me in Task 2 of 3. However, I'm not getting Task 3 of 3 to work yet. Your approach of working inside CapitalismHand is probably better.
Trace Harris
Python Web Development Techdegree Graduate 22,065 PointsSo looking at your code you need to put dunders under your initial init and then the init that you over ride your code should look something like this:
class CapitalismHand(Hand):
def __init__(self, *args, **kwargs):
super().__init__(size=2, die_class=D6, *args, **kwargs)
Bob Prestridge
8,400 PointsBob Prestridge
8,400 PointsThank you for your response.
I added dunders, but I am still getting an error:
ValueError: You must provide a die class
I've added the die class (D6); and the code still doesn't work.
Can anyone please provide insight?
Thanks!