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 trialOscar de Lima
1,963 Pointsdont understand the second part please help
what are the arguments?, what are the attributes?
import re
string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''
players = re.search('''^(?P<last_name>\w+\s?\w+?),\s(?P<first_name>\w+\s?\w+?):\s(?P<score>\d*)$''', string, re.X|re.M)
class Player:
def __init__(self, **kwargs):
last_name = kwargs['last_name']
first_name = kwargs['first_name']
score = kwargs['score']
2 Answers
Unsubscribed User
3,273 PointsEdit: I just looked at your actual question. You may ignore the rest of my explanation if you like but I am not deleting it since it should help others who are asking about the same challenge. The arguments are the last_name, first_name, and score (the values for these variables mind you not the variables themselves).
I realize that there are cleaner & more pythonic ways to answer this question but sometimes when you are programming you just need to solve a problem. You can make it fast and pretty later (in that order of importance).
Remember, all the challenge is asking you to do is make it so the three variables can be modified via the init method. Ask yourself, what is the easiest way to do this?
The most simplistic solution is this:
class Player:
def __init__(self, last_name, first_name, score):
self.last_name = last_name
self.first_name = first_name
self.score = score
This solution clears all the requirements set by the challenge and involves the least depth in your programming. It does assume that the variables last_name, first_name, and score will be called as simple arguments in that sequence.
If the arguments were dictionary objects (ie. "last_name": "Python", "first_name": "Monty", "Score": 42) then you would use the **kwargs argument in your init method as follows:
class Player:
last_name = {}
first_name = {}
score = {}
def __init__(self, **kwargs):
for key, value in kwargs:
self.key = value
In this case since the **kwargs approach didn't work (I tried it at first too) I tried simply working with the arguments in sequence, which worked. Since the arguments were simply formatted 3 values separated by commas (which was proved by my first example being successful) we could also access them using the *args argument which is what I will try next just for practice.
man odell
1,905 Pointsstring in your program is attribute and the arguments is that variable we sent to a function same as def show_my_name(name): # name is argument , u used that in your code print name