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 trialmarcolamoon
16,915 PointsHELP with challenge!!
Our Student class is coming along nicely!
I'd like to be able to set the name attribute at the same time that I create an instance. Can you add the code for doing that? Remember, you'll need to override the init method.
class Student:
name = "Your Name"
def __init__(self, name=None, **kwargs):
super(Student,self).__init__()
self["name"]=name
for key, value in kwargs.items():
setattr(self,key,value)
def praise(self):
return "You inspire me, {}".format(self.name)
def reassurance(self):
return "Chin up, {}. You'll get it next time!".format(self.name)
def feedback(self, grade):
if grade > 50:
return self.praise()
return self.reassurance()
3 Answers
Jeanette Brown
20,485 PointsFor anyone who needs help this worked for me
class Student:
name = "Your Name"
def __init__(self, name= "Your Name", **kwarg):
self.name = name
for key, value in kwarg.items():
setattr(self, key, value)
def praise(self):
return "You inspire me, {}".format(self.name)
def reassurance(self):
return "Chin up, {}. You'll get it next time!".format(self.name)
def feedback(self, grade):
if grade > 50:
return self.praise()
return self.reassurance()
AJ Salmon
5,675 PointsFor task one, you won't need kwargs in your init. You just want to have name in there, so that when someone creates an instance of the class, the name attribute is set to whatever is passed to the class when it's created. You can use name=None, or simply name, in the parameter of init. It should result in this output:
>>> marcolamoon = Student('Marco')
>>> marcolamoon.name
'Marco'
(You can test this in workspaces)
Matt Fredericks
5,399 PointsI think this is the only part which was required for task 1 of 2 def init(self, name= "Your name"): self.name = name
Patrick Altman
6,173 PointsPatrick Altman
6,173 PointsThank you Jeanette.