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

Sabine Lazuhina
Sabine Lazuhina
2,334 Points

TypeError: score_yatzy() missing 1 required positional argument: 'set_size'

I am trying to solve the challenge in my own messy but logical way (the way I understand) but I don't understand why does it keep on throwing the same TypeError about the missing positional argument. I think I have provided it ..

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):
        for item in self._score_set(hand, 5):
            if hand[0] == hand[1] and hand[1] == hand[2] and hand[2] == hand[3] and hand[3] == hand[4]:
                return 50
            else:
                return 0

2 Answers

Steven Parker
Steven Parker
229,644 Points

You have required that argument, but you don't use it. And the challenge is not expecting (or providing) it when it tests the function.

Also, you won't need a loop.

Ross Coe
Ross Coe
5,061 Points

I figured it out but can you explain set_size (is that the number of dice used?? = so in Yatzy set_size by default is 5).. but that's confusing in relation to its use in the _score_set method??

I don't really understand that conditional

     if count == set_size