Daniel Mula Tarancón9,691 Points
Hi everyone! I would like some help with my code.
I believe that the question maybe is not well defined.
The part in which I am interested is the init part. I think this should be the right answer:
def init(self, is_hungry): self.is_hungry = True
However, according to the question I can only put "self" inside the brackets. Either it doesn't make sense or I am wrong and I don't see it.
Thanks for helping me.
# insert your code here class Panda(): species = 'Ailuropoda melanoleuca' food = 'bamboo' def __init__(self): self.is_hungry = True
In this case, you don't need to pass in an is_hungry parameter/argument because they just want the value of self.is_hungry to be True by default for every instance of the Panda class.
Of course, if you were making your own Panda class (in the real world), you could pass in an is_hungry parameter/argument, but if you did, you'd use it like this:
# insert your code here class Panda(): species = 'Ailuropoda melanoleuca' food = 'bamboo' def __init__(self, is_hungry): self.is_hungry = is_hungry # The passed-in value, not a hard-coded True my_panda = Panda(False) print( my_panda.is_hungry )
Which will print:
Code which I tested (and you can test, too, if you want) here: https://www.katacoda.com/courses/python/playground
Of course, in the real world, it would also make sense to do some kind of validation on is_hungry, to make sure the passed-in value is a boolean, and not any other data type.
You'll likely understand it better when you do this upcoming challenge:
And for best results, make sure all your indentation is in multiples of 4 spaces precisely (don't use tabs), such as 4, 8, 12, 16, 20, etc. (Python is strict about it since it uses indentation instead of curly braces to determine/define a logical code block).
I hope that helps.
Stay safe and happy coding!