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

How do you know what the player argument will be like?

I don't really get the question again!...

Add a score method to Game that takes a player argument that'll 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).

... how do I know what the player argument will be like? Is it is tuple- like one value for each player? (which is suggested with the info about needing to adjust the index)

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

  def score(self):
    # do some check on player/ player arg 
    self.current_score = self.current_score + 1 

2 Answers

Dan Johnson
Dan Johnson
40,532 Points

The description states the value for player will be restricted to 1 or 2. The comment about adjusting the index is to show that the players' number is not zero based like their score, e.g. player 1's score is stored at index 0 of self.current_score, so you'll need to account for that.

Here's one way to select between the players:

  def score(self, player):
    # This can be reduced to one line
    if player == 1:
      # ...
    else:
      # ...

Hmm... I still don't like the question tbh!

It doesn't really explain what current_score is... if it is a tuple of two players scores or different types of score- I can't see the link with the video beforehand too