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 trialluke hammer
25,513 PointsPython inheritance question
This is the question form the test. 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). You do not need to define self.score. It comes from the Game class.
I don't know how to debug and see what is happening wrong here.
from game import Game
class GameScore(Game):
def __str__(self):
score = self.score.self.score
message = "Player 1: {0} Player 2: {1}".format(score[0],score[1])
print("this is a test")
return message
3 Answers
Cory Madden
7,120 PointsYou don't need to redefine score there, and if you were to that's not how you would do it. self.score doesn't have a property called "self" so that's not going to succeed. However, the format logic looks sound.
luke hammer
25,513 PointsSo i attempt this but this also does not work.
from game import Game
class GameScore(Game):
def __str__(self):
#score = self.score.self.score
message = "Player 1: {0} Player 2: {1}".format(self.score.self.score[0],self.score.self.score[1])
return message
Cory Madden
7,120 PointsYou're still doing:
self.score.self.score
Just do:
self.score
luke hammer
25,513 PointsCool got it!! thank you !!
Jeremy Kerrigan
12,002 PointsI 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)
Mehran Moradi
11,140 PointsI still could not solve this problem #kenneth
luke hammer
25,513 Pointsluke hammer
25,513 Pointscool got it