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

Abhishek Gangadhar
Abhishek Gangadhar
9,467 Points

Cant Find why I'm not getting through this challenge

I need to increment the current_score with respect to the input of player. Not understanding what i did wrong

game.py
class Game:

  def score(self,player):

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



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

3 Answers

Josh Keenan
Josh Keenan
20,315 Points
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
    else:
      pass

Here's my code to the challenge, it works as it's simple Keep code simple! You can simply test to see if the argument is 1 or 2, yours is probably fine except for the last else statement, you don't need it to be recursive and the player argument isn't passed into it then!

Abhishek Gangadhar
Abhishek Gangadhar
9,467 Points

Hey Josh, Your code worked, But dont we need to call the function in order for it to work?

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Hi Abhishek, your original code is very close to correct. Remove that last else:

class Game:

  def score(self,player):

    if player in [1,2]:
      if player == 1:
        self.current_score[0] += 1
      else:
        self.current_score[1] += 1
    # This else is unnecessary. If 'player' not 1 or 2 do nothing.
    #else:
    #  self.score()

  def __init__(self):
    self.score(self.player)
    self.current_score = [0, 0]
Josh Keenan
Josh Keenan
20,315 Points

No you don't, this is because the challenge is simply to create the function, the code challenge is just to test you understand the principles of the last video's lesson. In later challenges you may need to call the methods, but don't do so unless it explicitly asks you to do so!