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 Score Method

chiu szu ting
chiu szu ting
2,318 Points

the answer didn't work when i run it outside the quiz area

def score(self,player): if player == 1: self.current_score[0]+= 1
elif player == 2: self.current_score[1]+= 1

this passed the quiz,but when i move it to the 'real' python space,the current_score always returns [0,0], so .....how to correct it?

1 Answer

Ryan S
Ryan S
27,276 Points

Hi chiu szu ting,

How are you running it outside of the quiz area? Are you creating an instance of Game and passing in the required arguments?

The code works fine for me. Here are the steps to test it in the python shell:

>>> from game import Game    # First import the Game class from game.py (or whatever you named the file)
>>> new_game = Game()        # create new instance of Game
>>> new_game.current_score   # check initial current score
[0, 0]
>>> new_game.score(1)        # Pass in "1" to represent player one
>>> new_game.current_score   # check current score again
[1, 0]
chiu szu ting
chiu szu ting
2,318 Points

thank for the shell teaching~i think i did some mistakes at that time but now i everything works fine^ ^ thank you!