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 trialDhruv Ghulati
1,582 PointsHow to make player 1 and player 2 variables within the Game class?
I tried doing this exercise and my roadblock I guess is how do I a) make player a variable in my methods and b) how can I specify player - is it the index of the tuple self.score?
class Game:
def __init__(self):
self.current_score = [0, 0]
def score(self):
self.current_score[0]=self.current_score[0]+1
self.current_score[1]=self.current_score[1]+1
1 Answer
Kenneth Love
Treehouse Guest Teacherscore
is going to get a number, either 1 or 2. Use that number to update the correct member of the self.current_score
attribute. You don't need to update both members.
And you make player a variable in a method just like you do in a regular function. The only difference is that self
needs to come first.
Dhruv Ghulati
1,582 PointsDhruv Ghulati
1,582 PointsDONE! Thanks. The thing I didn't realise is that player is linked to score e.g. the index of score is player -1.