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 trialIsaac John
7,516 Pointsscore method test
class Game:
def __init__(self):
self.current_score = [0, 0]
def score(self):
new_current_score = self.current_score[0] + 1, self.current_score[1]+1
return new_current_score
http://teamtreehouse.com/library/score-method
Isn't this supposed to work? I tried the code itself in workspaces and it returns tuples (1,1) I thought (self) is used to pass attributes to instances. wouldn't the (self) be the same as (player/players)?
3 Answers
Kenneth Love
Treehouse Guest TeacherYou're close. Your score()
method needs to accept a player, either 1 or 2, and then update their score accordingly. You don't need to return anything from score()
but you will need to correct the player number to their position in the current_score
list.
Anthony Liu
11,374 PointsI got confused on this too. It is actually a game between player 1 vs player 2
You want an output along the lines of [0,1] or [1,0]
Isaac John
7,516 Pointsclass Game:
def __init__(self):
self.current_score = [0, 0]
def score(self):
player_1 = input('Enter Name') #accepts player 1
player_2 = input('Enter Name') #accepts player 2
player_1, player_2 = self.current_score #assigns players to scores as in tuples
player_1 = self.current_score[0] + 1 #increases player 1's score
player_2 = self.current_score[1] + 1 #increases player 2's score
So I tried something but I get the try again message. I guess my problem is that I don't know how to accept a player besides input()
Kenneth Love
Treehouse Guest TeacherYour score()
method needs to look for a player
argument.
def score(self, player):
You won't even need to use input()
or print()
to pass one of my code challenges.
Isaac John
7,516 PointsIsaac John
7,516 Pointssir besides input() is there another method i can use to accept the players?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherIsaac John How do methods/functions take in information? Through arguments. You need to add more arguments to your method, like I explained below.