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__

Jonathan Endersby
Jonathan Endersby
9,807 Points

Do I need to split the tuple?

I stuck on this part of the code challenge.

The syntax comes up with whats expected and what is shown, but I don't know if I have to split the tuple to give the player 1 score and the player 2 score.


from game import Game

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

2 Answers

Ryan S
Ryan S
27,276 Points

Hi Jonathan,

You are really close. You will need to pull out the each value separately in the self.score tuple.

You can do this one of two ways. Either access each score value by index, eg. self.score[0], self.score[1], or you could unpack it using the * operator.

Also, you will need to recheck your returned string. It must be exactly as the challenge asks, punctuation and all.

Good luck.

Christopher Shaw
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 Points

You almost have it.

  1. After player 1, you have a , where it should be a ;

  2. You can get the tuple values using self.score[0] and self.score[1]

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