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 Object-Oriented Python (retired) Inheritance Score Method

Help me out, what am I missing?

There is obviously something wrong and I quite cant put my finger on it.

game.py
class Game:
    def __init__(self):
        self.current_score = [0, 0]

    def score(player):
        if player == 1:
            self.current_score[0] = self.current_score[0] + 1
        elif player == 2:
            self.current_score[0] +=1
        else self.current_score = self.current_score

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi Mduduzi,

1) The error we get from this code is 'Bummer! SyntaxError: else self.current_score = self.current_score'. We can start by taking out that line, since even the compiler did allow it to run, all we would be doing is setting current_score to itself, which it already theoretically would be.

2) After we do that, we get the generic 'Bummer! Try again!' error. The reason for this is because we are not allowing 'self' to be passed to the score method, in our method declaration. The 'self' parameter has to be written before the 'player' parameter in the function header (if we are going to operate on 'self', we need to immediately state it as a parameter in the method header.)

3) Finally, we get an error message of 'Bummer! Score didn't increase correctly. Expected [0, 1], got [0, 0].' This suggests that our code theoretically would be compiled and run, but we aren't getting the result that we're logically looking for. The reason for this is because, in our elif clause, we still seem to be updating self.current_score[0]. Since we are updating the current_score for player 2, that index should be a 1 instead.

class Game:
    def __init__(self):
        self.current_score = [0, 0]

    def score(self, player):
        if player == 1:
            self.current_score[0] += 1
        elif player == 2:
            self.current_score[1] += 1

Hope this helps!

Thankyou