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

Ladonna Hill
Ladonna Hill
1,576 Points

Bummer! Did you create the `score` method?

What am I missing? I don't understand why I am getting this error message. It looks to me like I have created the 'score' method. Am I way off base or what? Can someone please help?

game.py
class Game:

  def score(self, player):
    player = input("Input 1 or 2: ")
    return player

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

2 Answers

Hey Ladonna,

You are doing great! You are just dealing with something confusing.

You are suppose to create your method after the constructor method. Also you need to make decisions, so I used the if statement. So if player is 1, I am increasing index [0], if it is player 2 I am increasing index [1]. Here is an example.

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

Keep in mind that we are representing/storing the current score of player 1 as index [0] and player 2 as index [1]. This worked for me :)

-Dan

Ladonna Hill
Ladonna Hill
1,576 Points

Thanks Dan :)

I will give that a try.

Ladonna

Ladonna Hill
Ladonna Hill
1,576 Points

Hey Dan,

I tried it and it worked! Thanks so much :)

Ladonna

You are always welcome!

Denny Ho
Denny Ho
4,472 Points

Hi Dan, I was working on this problem and got the same code you did independently. However, my code does not work. It actually gives the same error message of Bummer! did you create the score method?

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

  def score(self, ind):
    if ind == 1:
      self.current_score[0] += 1
    elif ind == 2:
      self.current_Score[1] += 1

any ideas? sorry to sorta hijack the thread.

Denny Ho
Denny Ho
4,472 Points

a capital 'S" in current_score in my elif statement. my eye caught it right when i posted it. sorry. thanks