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 __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,132 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,868 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,132 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.