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

Please help me solve this challenge. I am stuck here

I want to solve this challenge and have used almost everywhere's forum and could not solve. Please help

game.py
class Game:

    def __init__(self):
    self.current_score = [0, 0]
    def score(self,player):
        self.player = player

            if self.player == 1:
        self.current_score[0] +=1
        elif self.player == 2:
            self.current_score[1] += 1
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Mehran! Sorry I couldn't get to your help request sooner, but I see that Idan Melamed has helped out with a couple of brilliant explanations. Glad you got it working! :sparkles:

3 Answers

Idan Melamed
Idan Melamed
16,285 Points

Hi Mehran

The argument player will be either 1 or 2. If it's 1, we need to increase current_score[0] by 1. If it's 2, we need to increase current_score[1] by 1.

One solution to this could be:

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

    def score(self, player):
        self.current_score[player - 1] += 1

Thanks Idan. I was stuck there and it worked. Could you please explain more why only one player you wrote?

Idan Melamed
Idan Melamed
16,285 Points

Hi Mehran, Sure, I can try.

The instructions said that "player" is an argument, and it will be either 1 or 2. So every time you see the argument "player", you have to remember it will only be either the number 1, or the number 2.

So, we could write:

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

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

I just wrote it a little differently, but it's basically exactly the same.

Thanks #Jennifer Nordell. Really Appreciate