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 trialTucker Fischer
10,517 Pointscreate an instance attribute called is_hungry and set it equal to True.
Add an init method to your class. It should only take the self argument. Inisde the method, create an instance attribute called is_hungry and set it equal to True.
Here is my code. Where do you think I went wrong?
class Panda: species = 'Ailuropoda melanoleuca' food = 'bamboo' hungry = True
def __init__(self, hungry):
self.hungry = hungry
is_hungry = Panda('True')
class Panda:
species = 'Ailuropoda melanoleuca'
food = 'bamboo'
hungry = True
def __init__(self, hungry):
self.hungry = hungry
is_hungry = Panda('True')
1 Answer
Megan Amendola
Treehouse Teacherclass Panda:
species = 'Ailuropoda melanoleuca'
food = 'bamboo'
def __init__(self):
self.is_hungry = True
You should just be creating an instance variable set to True
like so.
This code: is_hungry = Panda('True')
creates a variable called is_hungry
that holds an instance of the Panda class where you have set the value of the is_hungry
instance attribute to 'True'
which is a string not a boolean.
Michael Jones
Python Development Techdegree Graduate 38,554 PointsMichael Jones
Python Development Techdegree Graduate 38,554 PointsAfternoon,
Sorry, but I'm a little confused to why you added a class attribute to the class. The second question said - "Add an init method to your class. It should only take the self argument. Inisde the method, create an instance attribute called is_hungry and set it equal to True."
So isn't that asking us to to create an init method within the class and create a default value within? So shouldn't it look like below?
Hope you can help. :)
Paul H T
19,747 PointsPaul H T
19,747 Pointsdef init(self, is_hungry = True):
self.is_hungry = is_hungry
This should have been the answer... You guys need to fix it
-> or you need to have a video response to explain your logic which is completely different from the video lesson about the instance attribute