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 __str__

Sergei Miroshnikov
Sergei Miroshnikov
3,313 Points

Bummer try again is very descriptive message , helps a lot to understand the problem clearly

I am doing the challenge, I do not understand what is wrong :)

game_str.py
from game import Game

class GameScore(Game):
  pass

  def  __str__(self):
    return 'Player 1:{};Player2:{}'.format(self.score.self.score)

2 Answers

Daniel Johnson
Daniel Johnson
104,131 Points

First, you'll need to remove pass from the str method. Then you'll need to format your string with the exact spacing as in the challenge. Also in your format function you used a period where you should've use a comma to separate the values, and these values are arrays as well so you'll need to access the individual values.

game_str.py
from game import Game

class GameScore(Game):
    def __str__(self):
        return 'Player 1: {}; Player 2: {}'.format(self.score[0], self.score[1])
William Li
William Li
Courses Plus Student 26,865 Points

yes, alternatively, we can unpack the array using format(*self.score).

Sergei Miroshnikov
Sergei Miroshnikov
3,313 Points

Thank you, score is a tuple where first element is Player 1 score and second element is Player 2 score?

Daniel Johnson
Daniel Johnson
104,131 Points

Yes. Basically, score is a list of values, so you don't want to just put the entire list of values. Instead, you'll want to put only individual values from the list.