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 trialTal Reznic
4,633 PointsAdd a __str__ method to GameScore that returns the score in the string "Player 1: 5; Player 2: 10", using the correct va
Can i get help with this question please
from game import Game
class GameScore(Game):
def __str__(self):
return "Player1:{};Player2:{}".format(self.score)
3 Answers
Bryan Laraway
13,366 Pointsp.s. Perhaps an even better way to do it than what I have above is to unpack the tuple like this:
from game import Game
class GameScore(Game):
def __str__(self):
return "Player 1: {}; Player 2: {}".format(*self.score)
Bryan Laraway
13,366 PointsHere's what worked for me:
from game import Game
class GameScore(Game):
def __str__(self):
return "Player 1: {}; Player 2: {}".format(self.score[0], self.score[1])
Remember that the self.score is a tuple that needs to be unpacked.
Chris Grazioli
31,225 PointsThis unpacking thing kills me every time... I don't remember it until I look at the Community boards... then I'm like OHHH yeah those stupid *args for tuples and **args for dicts