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 trialDawid Cedrych
15,108 PointsTask 1 no longer passing in code challenge: __str__
from game import Game
class GameScore(Game):
def __str__(self):
return "Player 1: {}; Player 2: {}".format(self.score[0], self.score[1])
I can't figure it out what is wrong here, please give me some advice
Thanks in advance
2 Answers
Kenneth Love
Treehouse Guest TeacherLooks like you didn't indent the body of the function.
durul
62,690 Pointsfrom game import Game
class GameScore(Game):
def __str__(self):
self.score = (5, 10)
return "Player1: {}; Player2: {}".format(self.score, self.score)
Kenneth Love
Treehouse Guest TeacherWell, self.score
is a tuple, so you're going to end up with `"Player1: (5, 10); Player2: (5, 10)", which isn't what you want. How do you get to the members of a tuple/list?
durul
62,690 Pointsmy code is pass :)
Rune Larsen
25,877 Pointsfrom game import Game class GameScore(Game): def str(self): self.score = (5, 2) return "Player 1: {}; Player 2: {}".format(self.score[0], self.score[1])
This solved the code challenge for me, but for some reason, I don't think that it was the way it was supposed to work, as the code challenge say "self.score is a tuple with Player 1's score and Player 2's score like (5, 10)." Please give me some hints to help me solve it correctly.
Kenneth Love
Treehouse Guest TeacherRune Larsen Ideally, you'd just unpack the tuple into the .format()
call. Something like:
return "Player 1: {}; Player 2: {}".format(*self.score)
Also, you don't need to define self.score
. It comes from the Game
class.