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

I'm not sure what I did wrong on chance scoring part 2

Can anyone explain what I did 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):
        _sum = 0
        for number in hand:
            _sum += number
        return _sum

    def score_yatzy(self, hand):
        for count in hand._sets.values():
            if count == 5:
                return 50
        return 0

4 Answers

Steven Parker
Steven Parker
229,644 Points

I tried pasting your code directly into the challenge, and it passed!

Try restarting your browser and then paste it in yourself.

Thanks, I have been having that glitch a ton recently where treehouse says I have the wrong code and it is fine.

Steven Parker
Steven Parker
229,644 Points

Just curious, do you happen to be using a chromebook?

No, Iā€™m on a Mac

horus93
horus93
4,333 Points

Steven is our resident saint ;) , but yea, this particular set of challenges has seemed a bit buggy. I noticed it several times tonight registering me as having the wrong code when i had to refresh the browser, copy pasting all the original working stuff I had back into it. Then the only way I got it working again was going in, changing some small thing to be wrong, submitting it, then fixing it and resubmitting it. This is the kinda stuff that'll drive you mad when you're trying to figure out what you're doing wrong.

Chul Kim
Chul Kim
2,341 Points

I was wondering if anyone can explain the code "hands._sets.values()" written under the score_yatzy method.

I understand that the _sets method returns a dictionary and the .values() calls a list of the values. I thought that you would have to write hands._sets().values() to call both methods.

Just to clear things up, when calling more than one method on an object/class do you only use the parenthesis to call on the last method?

Steven Parker
Steven Parker
229,644 Points

The "_sets" in the example is a property of the "hand" object, not a method. That property has a "values" method which is being called.

Any call must include parentheses after the method name. While not being done in this example, it is possible to call more than one method at a time if each intermediate method is designed to return a pointer to the object. This technique is called "method chaining".

Chul Kim
Chul Kim
2,341 Points

Thank you for the clarification!