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

Tiana Manzano
PLUS
Tiana Manzano
Courses Plus Student 2,248 Points

score_yatzy

I'm not 100% sure how to make it check that each dice have the same value. I've been trying to search outside sources, hence the "all" but I don't seem to be getting closer to a solution.

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, set_size=5):
        if all in self.hand == hand[0]:
            return 50 
        else:
            return 0

1 Answer

Steven Parker
Steven Parker
229,708 Points

There's no "all" defined here, but if you wanted to check each item of a list you might do it with a loop. And remember that "hand" is passed as an argument (so no "self." prefix needed).

Also, the instructions don't ask for a "set_size" argument.

Tiana Manzano
Tiana Manzano
Courses Plus Student 2,248 Points

I guess what I'm confused about is how I can instruct it to check if all of them are the same, like I understand that it'll check for each item in sequence but I'm confused about how I would go about saying:

for x in hand: if (all items) == (same thing): return 50

See what I mean? I don't know it would compare each item in a list to be similar which is why i tried to use "all"

Thank you so much for your help and patience!

Steven Parker
Steven Parker
229,708 Points

The loop is a good idea, and then you might compare each item to the next one and return 0 if any do not match. Only if they are all the same would you return 50:

        for x in range(len(hand)-1):
            if not hand[x] == hand[x+1]:
                return 0;
        return 50;