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

Y B
Y B
14,136 Points

Score method doesn't pass

I'm not sure why this score method doesn't pass - it only says try again. If I try it as a list outside a class that seems to work, but not within unfortunately?

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

  def score(self):
    self.current_score[0]= self.current_score[0] + 1

4 Answers

Mikael Enarsson
Mikael Enarsson
7,056 Points

The key to this problem is that you have to be able to choose which player's score to increase. So, your function header should take two arguments, self and one more, e.g. player

def score(self, player)

The rest is fine, just adjust for being able to choose player ^^

Y B
Y B
14,136 Points

Thanks, wow am I finding the questions on this course incredibly frustrating and really vaguely defined - maybe it's just me.

anyway this doesn't work either. What is the player argument; an int between 0 and 1 or 1 and 2?

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


  def score(self, player):
    self.current_score[player] = self.current_score[player] + 1
Mikael Enarsson
Mikael Enarsson
7,056 Points

Look in the description, the player value is passed in as either 1 or 2, but list starts from 0, i.e. player 1 is at index 0 and player 2 at index 1.

And I agree, some questions are nigh incomprehensible.

Y B
Y B
14,136 Points

Thanks

Mikael Enarsson
Mikael Enarsson
7,056 Points

No problem ^^ I hope you didn't find my answers to vague, I tend to prefer to attempt to guide to the solution rather than just give the solution.

Y B
Y B
14,136 Points

No no at all that's fine, I didn't realise that player 1,2 meant it would be an input

Done now thanks for your help.