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

Bubbly Sprout
Bubbly Sprout
2,472 Points

I got "No score_chance method" with the following code. It works in the workspace. Not sure why it doesn't work here.

import hands

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 hand.total
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 hand.total

2 Answers

Josh Keenan
Josh Keenan
19,652 Points

Instead of using hand.total try using sum() as your hand class inherits from the List class it will be able to work with it.

    def score_chance(self, hand):
        return sum(hand)
Bubbly Sprout
Bubbly Sprout
2,472 Points

Thanks! My trouble is that my code works in the workspace, but when I input the same code as an answer to the challenge problem, it said "no score_chance method". The same thing happened with other code challenges too recently. I'm thinking it must be a set-up issue. Has it ever happened to you?