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

Einars Vilnis
Einars Vilnis
8,050 Points

Score Challenge.

What am I doing wrong on my system it works as asked .

game.py
class Game:
  def score(self):
    playerScore = [0, 0]
    player = input("1, or 2: ")
    if player in '12':
        if player == '1':
            playerScore[0] += 1
            return 'Current Score: {}'.format(playerScore)
        else:
            playerScore[1] += 1
            return 'Current Score: {}'.format(playerScore)
    else:
        return self.score()

  def __init__(self, **kwargs):
    self.current_score = self.score()

    for key, value in kwargs.items():
      setattr(self, key, value)

1 Answer

There are few basic things wrong with your code.

First of read the question properly. It specifically says that your score method should take in the PARAMETER/ARGUMENT player. Not ask user for this info (would that makes sense in a real game?)

second you don't need to return anything.
and you can just use the indexes to your advantage & have a succinct answer e.g.

self.current_score[player-1] += 1

but really that is all you need in your score function!