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 trial

Python

MONTRIAL HARRELL
seal-mask
.a{fill-rule:evenodd;}techdegree
MONTRIAL HARRELL
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?

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 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!

MONTRIAL HARRELL
seal-mask
.a{fill-rule:evenodd;}techdegree
MONTRIAL HARRELL
Python Web Development Techdegree Student 2,150 Points

Nick

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