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__

I am not sure why I am getting a self.score.self.score... what does this mean?

I am not sure what I am supposed to do here... can I just write "Player 1" and "Player 2" or should I be pulling this from the object somehow?

Bit confused all around really!...

game_str.py
from game import Game

class GameScore(Game):
  pass

  def __str__(self):
    return "Player 1: {}, Player 2: {}".format(self.score.self.score[0], self.score.self.score[1])

8 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

ahhh I see, yeah no you have to read really slooowwww lol. It says "using the correct values from self.score. PERIOD end of sentence kind of period. New sentence self.score xxxx

I totally see how you thought that tho.

Does that clear it up?

Ahhh... ok, I see where I went down a not so merry path there !

All clear now (and the got the exercise passed)... thanks for the help Ryan =)

Ryan Ruscett
Ryan Ruscett
23,309 Points

No worries, I do that all the time. The craziest little hang ups.

Ryan Ruscett
Ryan Ruscett
23,309 Points

What is different about these two strings.

Top one is expected bottom one is what you are giving. Notice anything HINT ( ; ) missing.

Player 1: 5; Player 2: 2
Player 1: 5, Player 2: 2

update your return to add the missing character.

Sung Uk Ryu
Sung Uk Ryu
5,304 Points

I actually copied the string part from the problem itself and it worked magically... -.- Thanks for the truth! :D

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

So you are close. You are calling the values wrong.

return "Player 1: {}, Player 2: {}".format(self.score.self.score[0], self.score.self.score[1]

Why are you calling it twice for each item. self.score.self.score? You only call it one time. So like this

return "Player 1: {}, Player 2: {}".format(self.score[0], self.score[1]

NOTE - I would recommend saving that as say variable XYZ = blahblah and returning XYZ. That way if something ever goes wrong you can always just add a print statment on XYZ and get the actual value that is being passed. Helps if you use repr too. Least for me.

That's all you have to do differently. There is one other error that will be way to clear when you see it about your string. You are missing a ; inside the string.

Let me know if you have any other issues I can clear up.

I was calling it twice as the question seemed to suggest to do that...

Here is the question as it was presented to me: "Add a str method to GameScore that returns the score in the string "Player 1: 5; Player 2: 10", using the correct values from self.score. self.score is a tuple with Player 1's score and Player 2's score like (5, 10)."

... so the "self.score.self.score" in there had me confused- why is it like that? (or is that a mistake??)

Sung Uk Ryu
Sung Uk Ryu
5,304 Points

Hi,I have same error and don't know why.

I tried both

from game import Game

class GameScore(Game):
  def __str__(self):
    return "Player 1: {}, Player 2: {}".format(*self.score)

and

from game import Game

class GameScore(Game):
  def __str__(self):
    return "Player 1: {}, Player 2: {}".format(self.score[0], self.score[1])

and I got message

Bummer! Expected "Player 1: 5; Player 2: 2". Got "Player 1: 5, Player 2: 2". ?????

for both....

What should I do now -.-

I got this same error. I refreshed the page and it worked.

Both of them should work fine. You have typed: return "Player 1: {}, Player 2: {}".format(self.score[0], self.score[1])

Just change this to: return "Player 1: {}; Player 2: {}".format(self.score[0], self.score[1])

Need to add (;) instead of (,) between two players as required and it works fine.

from game import Game

class GameScore(Game): def str(self): return "Player 1: {}; Player 2: {}".format(self.score[0], self.score[1])

Casey Huckel
PLUS
Casey Huckel
Courses Plus Student 4,257 Points

How is this wrong? It says Task 1 is no longer passing:

from game import Game

class GameScore(Game): pass

def_str_(self): return "Player 1: {}; Player 2: {}".format(self.score[0] , self.score[1])

Jeremy Kerrigan
Jeremy Kerrigan
12,002 Points

I solved it like this by unpacking the tuple into 2 separate variables x, y

from game import Game

class GameScore(Game):
  pass

  def __str__(self):
    x, y = self.score
    return "Player 1: {}; Player 2: {}".format(x, y)