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!

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 __str__


Add a str method

from game import Game
class GameScore(Game):
  def __str__():
    return "Player {}; Player {}".format(self.score, self.score)

1 Answer

Steven Parker
Steven Parker
225,730 Points

Here's a few hints:

  • you won't need pass anymore when you define the method
  • you forgot to include the player numbers followed by colons in the literal string
  • since self.score is a tuple, you'll need to use indexing to get the individual player scores
  • a method should indicate self as its first argument

I'll bet you can get it now. But if you're still stuck...


class GameScore(Game):
  def __str__(self):
    return "Player 1: {}; Player 2: {}".format(self.score[0], self.score[1])
Chris Freeman
Chris Freeman
Treehouse Moderator 68,390 Points

Big :+1: on the use of spoiler button. Moderator material!

Myers Carpenter
Myers Carpenter
6,421 Points

Thanks showing us you could add Javascript in your post. That isn't something we want to allow in the forums as it's a security risk (read more here in the Rails Security Guide). We've fixed the bug and edited your post.

I've added a feature request for a official spoiler button to be added into the forum code as I see it's usefulness.