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

Isaac John
Isaac John
7,516 Points

score 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
STAFF
Kenneth Love
Treehouse Guest Teacher

You'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.

Isaac John
Isaac John
7,516 Points

sir besides input() is there another method i can use to accept the players?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Isaac John How do methods/functions take in information? Through arguments. You need to add more arguments to your method, like I explained below.

Anthony Liu
Anthony Liu
11,374 Points

I 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
Isaac John
7,516 Points
class 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
Kenneth Love
Treehouse Guest Teacher

Your 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.