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

Andrew Gordon
Andrew Gordon
10,178 Points

Score Method Challenger 1/1

I feel like I am just having a moment, but I am really struggling with this question. I've tried going back and watching a few of the different videos, but nothing has clicked for me. the questions is: "Add a score method to Game that takes a player argument. The player argument will be either 1 or 2. Increase that player's value in self.current_score by 1. You'll need to adjust the index (i.e. player =1 means self.current_score[0] needs to increase)."

What I think should work is:

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

or maybe this, but I'm not sure how 'pass' truly works:

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

I would love just some hints to follow along with as I enjoy trying to piece the code together myself. I hope I'm going the right direction, but I think my logic gets a little eskewed. Appreciate any help!

Thanks, Andrew

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

  def score(player):

2 Answers

Christian Kuylen
Christian Kuylen
3,176 Points

I just copied and pasted your first code into the challenge and added the self argument and it went through. Are you sure your indentation and syntax are correct?

def score(self, player):
    if player == 1:
        self.current_score[0] += 1
    if player == 2:
        self.current_score[1] += 1
Andrew Gordon
Andrew Gordon
10,178 Points

So I just cleared it all and started a new instance of the challenge to make sure spacing was correct and it worked! Thanks for your help, glad I was on the right track to begin with haha!

Christian Kuylen
Christian Kuylen
3,176 Points

I'm pretty sure all of those would work, but remember that class methods need the argument self.

If you need more clarification, lemme know.

Andrew Gordon
Andrew Gordon
10,178 Points

Hey Christian,

Thanks for your response. You are right, I realized after posting that I needed:

def score(self, player)

but neither of the above listed formats will work still? I'm still at an impasse on this one!

Thanks! Andrew