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 trialJeff Vig
16,345 PointsThere has GOT to be a better way to identify what is wrong with the challenge instead of just "Bummer! Try again!"
Beating my head on the wall again!
Assuming a hand size of 5 for Yatzy, checking to see that the _score_set returns truthy for five values, should be enough. I tried checking that the hand size was 5.
I tried testing with 7 different hands. hand[:] = [one, three, three, four, four] hand2[:] = [one, one, one, one] hand3[:] = [one, one, one, two] hand4[:] = [one, one, one, one, one] hand5[:] = [one, one, one, one, two] hand6[:] = [one, one, one, one, one, one] hand7[:] = [one, one, one, one, one, two]
When hand size wasn't limited to 5, both hand4 and hand7 returned 50. When hand size was limited to 5, only hand4 returned 50.
class YatzyScoresheet:
def score_ones(self, hand):
return sum(hand.ones)
def _score_set(self, hand, set_size):
scores = [0]
for worth, count in hand._sets.items():
if count == set_size:
scores.append(worth*set_size)
return max(scores)
def score_one_pair(self, hand):
return self._score_set(hand, 2)
def score_chance(self, hand):
return sum(hand)
def score_yatzy(self, hand):
#if len(hand) == 5 and self._score_set(hand, 5):
if self._score_set(hand, 5):
return 50
return 0
2 Answers
Steven Parker
231,275 PointsThis code passes the challenge.
I just pasted it in and it passed! Try again?
But I agree those "Bummer" messages aren't always very helpful.
Jeff Vig
16,345 PointsNice! Two hours down the drain because of ... ?