Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.

Thanks

game_str.py
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
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,236 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])