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 trialIbrahim Mahmoud
714 PointsAll 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.
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
Treehouse Guest TeacherLike 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.
Ibrahim Mahmoud
714 PointsOk 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
Treehouse Guest TeacherNo because '12'
is a string and args1
will be an integer. Integers never have membership in a string.
Ibrahim Mahmoud
714 PointsOk, 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
Treehouse Guest TeacherBecause 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.
Ibrahim Mahmoud
714 PointsOh got it ok it needs to be an array that makes sense thanks!