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

No `score_yatzy` method

I have the method defined in the code. Why got this error:

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):
        for w, c in hand._sets.item():
            if count == 5:
                return 50
            else:
                return 0

1 Answer

Hi Peter,

If it says there's "no method", there's a syntax error.

Is it: for w, c in hand._sets.item(): this line? Should it be items()?

Steve.

Yes, that moves the error along. Next it says there's no count - that's because you've used c in this loop.

Then there's a new error that I've not figured out yet!

OK - I familiarised myself with this challenge.

I don't think you need to use a loop here. If you use the _score_set() method and pass in your hand and the number 5; if that comes back truthy, you have five identical hands. You could also test the length of the set (hand) as if it has a length of 1, there are five identical elements, i.e. one unique entry.

The first method is probably a little clearer as that's its purpose! Something like:

if self._score_set(hand, 5):
  # do the relevant returning

I hope that helps.

Steve.