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 trialY B
14,136 PointsScore 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?
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
7,056 PointsThe 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
14,136 PointsThanks, 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
7,056 PointsLook 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
14,136 PointsThanks
Mikael Enarsson
7,056 PointsNo 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
14,136 PointsNo 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.
Mikael Enarsson
7,056 PointsGlad to be of help ^^