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 Web Development Techdegree Student 2,150 Points

score_yatzy method giving incorrect score

I am trying to figure out why may score_yatzy method is giving the wrong score. My method checks the hand for 5 dice and if the modulus of the sum of the dice value has a remainder.

Where is my thought process going wrong?

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:
        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 sum(hand)%5 == 0:
            return 50
        return 0

2 Answers

I think the trouble is here that the method score_yatzy is only checking for the conditions of length == 5 and that the total is divisible by 5. Imagine a scenario where this is true, but should not be scored as a YAHTZEE! Example: 2,2,2,3,1 ; I would suggest testing all of the dice values to ensure they are equal to one another! Good luck and may the odds be ever in your favor!

Python Web Development Techdegree Student 2,150 Points


You helped me past my brain block. I changed my code and used a set to answer the question. My code ended up as the below and I was able to move one.

def score_yatzy(self, hand): test_yatzy = set(hand) if len(hand) == 5 and len(test_yatzy) == 1: return 50 return 0