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

Oprea Mihai
Oprea Mihai
5,592 Points

Score_Yatzy

Hy, If I tried it in my pycharm as simple method it worked.Here i got an error. Is because I don't use worth and count ?

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(int(Hand) for Hand in hand)
    def score_yatzy(self,hand):
    i=0
    for Hand in hand:
        if hand[i] == hand[i+1]:
            i=i+1
            if i==4:
                break
    if i == 4:
        return 50
    else:
        return 0

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

You are so close. The code within the body of the score_yatzy function needs to be indented on stop to be inside the function definition.

Post back if you need more help. Good Luck!!