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

Code is working in my environment but not through code challenge

I've set you up with all of the code you've seen in the course. I want you to add a score_chance method to the YatzyScoresheet. It should take a hand argument. Return the sum total of the dice in the hand. For example, a Hand of [1, 2, 2, 3, 4] would return a score of 12.

When I run this through Python in my terminal using the code that I wrote, it works everytime for different test cases. The test case in the example returns 12, etc.

What I'm I doing wrong? What am I missing?

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)

5 Answers

This code passed part 1 of 2 of this challenge for me ( I just copy/pasted your code). So im not sure what error you might be getting, part 2 of 2 doesnt pass but you haven't written that part yet.

Maybe just make sure when you are copy/pasting your code from your environment you arent picking up extra spaces or indentation before your defined class name. That might cause an error?

I restarted my browser, copied the code from my environment again, pasted it, and it passed.

Can't say I've ever had that happen in the hundreds of CCs I've done.

Either way, thanks, it's all working now.

Yeah, that's what I thought originally so I copy and pasted several times to no avail. Then deleted everything that I had pasted and typed it in. I get Try Again! everytime.

I'll try a few more things (not sure what exactly)...it's helpful to know I'm not crazy and that the code is correct.

Thanks guys just had the same bug