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

All I get from the challenge is "Bummer! Try Again!"

I don't know what I am doing wrong because it is not saying what is it that I am doing wrong.

game.py
class Game:
  def score(self):
    args1 = input("Score: ")

    if args1 in '12':
      if args1 == '1':
        return args1
      elif args1 == '2':
        return args1
    else:
      return self.score()

  def __init__(self):
    self.current_score = [self.score(), 0]

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Like the prompt says, your score method is going to get a player number, either 1 or 2. Increment that player's score by 1. You won't need input() and you don't need to return anything. Just update the value in the current_score attribute.

Ok I understand now. Shouldn't this code work?

class Game:
  def score(self, args1):

    if args1 in '12':
      self.current_score[args1 - 1] = self.current_score[args1 - 1] + 1

    pass

  def __init__(self):
    self.current_score = [0, 0]
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

No because '12' is a string and args1 will be an integer. Integers never have membership in a string.

Ok, I finally finished the challenge by taking out the "if args in 12:" line. Why does is work when I take it out? Thanks for your help so far.

class Game: def score(self, args1):

if args1 in 12:
  self.current_score[args1 - 1] = self.current_score[args1 - 1] + 1

pass

def init(self): self.current_score = [0, 0]

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Because 12 is an integer, not a container in which args1 could be found. You could do if args1 in [1, 2]: if you're really worried about bad information coming in.

Oh got it ok it needs to be an array that makes sense thanks!