This forum is now read-only. Please use our new forums! Go to forums
2.1: "NameError: name 'is_hungry' is not defined" yet I pass the test
My code:
# Class definition
class Animal(object):
"""Makes cute animals."""
# For initializing our instance objects
def __init__(self, name, age, is_hungry):
self.name = name
self.age = age
self.is_hungry = is_hungry
# Note that self is only used in the __init__()
# function definition; we don't need to pass it
# to our instance objects.
zebra = Animal("Jeffrey", 2, True)
giraffe = Animal("Bruce", 1, False)
panda = Animal("Chad", 7, True)
print zebra.name, zebra.age, zebra.is_hungry
print giraffe.name, giraffe.age, giraffe.is_hungry
print panda.name, panda.age, panda.is_hungry
Returns:
Traceback (most recent call last):
File "python", line 2, in <module>
File "python", line 8, in Animal
NameError: name 'is_hungry' is not defined
I still pass the excercise but that’s annoying cause I can’t see the code in action.
Answer 51596ba41431743782001354
Same here: it must be some trouble with the validator that I’m going to report now.
You seem to have the correct code, so rest assured and go on :)
Oh, on a side note it is just a matter of indentantion: cancelling the indentation at line 8, then riputting the tabs just works fine.
Answer 516d6fd188e7d398a2000346
I find this problem is about the space area at the line 2,3,4,5, I delete the space,and use Enter at the line 2,3,4,5 ,this problem is solved.
Answer 515dc1bd09019cf09f000024
Wht you suggested worked re the indentation, thanks
Answer 5160d6104919a138fc002747
Giacomo: I’m having the same problem, and I wasn’t able to fix it by deleting the existing indentation at line 8 and then inserting the tabs. It isn’t critical, but it is irritating… half the fun is solving the problem, and the other half is seeing the code work ;) Ciao! Daniel
1 comments
I tried just now and it works fine to me: try checking also other indentations, particularly on line 7.
Answer 516662eaa876694ac200241b
Yes the problem was with the indentation. I had to fix everything that is indented. I see this problem often when I copy some code from the classes course and paste it in Codecademy Labs. Codecademy Labs always has problem with the indentation of code in this course it seems.
Answer 5186742e93b555ef89004344
I have the same problem but i dont pass. i dont know why though.
1 comments
Remove any indentation up to line 8 and then put it again, it should fix it.
Answer 5193f667692e241f2b000cce
1 comments
Oh, Euridice - great nick. Tell me what error the system gives you and we’ll see what we can do.
Remember that also resetting the indentation on the line before the one in the error helps a lot.
Answer 536235788c1ccc5fbd001892
I don’t see any problem with your code. It’s only because I’m using Chrome. If you’re not using Chrome, then I don’t know what the problem is.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
9 comments
When I copy&paste the code into the exercise (on the old interface), it validates as correct.
The only way I could get this to validate without error was to convert all the indents to spaces in an external editor and then paste back in. Goddamn editor and style inconsistencies! XO
I had to cancel all the indentation and input it again, but that fixed it :)
Strange, as navigating it, it looked like all tabs…
I think it had some space hidden among tabs. Just guessing, though.
Thanks for letting me know about the indentation. Did you report this to the buggy exercises group?
PS All that was for Giacomo.
Yeah, we already discussed it in the buggy exercise group: it appears it happens with some old exercise when switching to the new UI.
It is the problem of the indentation from line 2 to 8.
Well, try doing tabula rasa: completely cancel every indentation and put it anew, so to fix it.