Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!