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

I can't seem to solve Game Score Challenge of Python OOP Class w/ methods that traditionally work with regular objects.

For some reason I cannot get the Score Method challenge to correctly recognize various logic incrementing the gamer score as instructed.

Even the most verbose yet correct way I know works for regular objects (trying it out seconds ago in the Python REPL) doesn't seem to work; perhaps Kenneth Love can clarify what gotcha I may not be seeing with my code involving instances of a class object in Python.

I do not get an error beyond Bummer! Try Again. The Python challenges seem to be correctly recognizing syntax errors just fine, so I don't know what else can be wrong with my code at this point.

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 
    else:
      self.current_score[1] = (self.current_score[1]) + 1 

3 Answers

I just realized this entire time it was asking for an instance method, not a class method. I recommend an error message that checks for that sort of mistake, as well as the challenge specifically stated that.

Problem solved.

Corrected code:

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


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

Just for fun:

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

as an instance method. Obviously this doesn't check against inputs above 2 players.

Is the game Desktop base or a Mobile base?