Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

There 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.

scoresheets.py
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
Steven Parker
215,939 Points

:white_check_mark: This 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.

Nice! Two hours down the drain because of ... ?