This forum is now read-only. Please use our new forums! Go to forums
Indentation Error [solved]
Does someone know why this error keep appearing?
Traceback (most recent call last):
File "runner.py", line 125, in compilecode
File "python", line 3
health = "good"
^
IndentationError: unexpected inden
Here is my code:
class Animal(object):
is_alive = True
health = "good"
def __init__(self, name, age):
self.name = name
self.age = age
def description(self):
print self.name, self.age
hippo = Animal('vini', 21)
sloth = Animal('joaquim', 20)
ocelot = Animal('clementina', 22)
print hippo.health, sloth.health, ocelot.health
I can’t figure out where is the error.
Answer 51b30d96631fe93a120069bc
Hi i had the same error. I just copied your the code below and it worked for me. Thanks.
Answer 51b74d8c631fe9756900b1c2
I have the solution to the problem You should only redo all the tabs in the code yourself then the problem is solved
Because Python use tab to recognize the structure of the code, so the error occurs when the tab is not correct
2 comments
It works for me, thank you!
thx!!
Answer 519b977ede46e4a03d003f84
I had this, probably spaces in there instead of tabs.
1 comments
thanks, it worked!
Answer 51a4dc8e271ead54fc000987
Banged my head on this for a while. Deleting every tab in a code (everything aligned to the left) and putting ‘em back worked for me…
1 comments
This worked for me also.
Answer 51a685b7393885f8b90026f5
Answer 51a70e1f9a526d0840004967
My tab length grew one space shorter, not sure why. But 4 mechanical spaces worked for me. Glad I could move on.
Answer 51afd12e282ae3b20b000134
I kept getting indent errors no matter what I did - deleting and reformatting white space was unsuccessful - until I added a space after init like so:
def __init__ (self, name, age):
Answer 51b8d0348c1ccced3b00069e
Answer 51c979e452f8632110001b11
I tried your code on my system with Python 3.3.2 and it gave following error: $ python test.py File “test.py”, line 8 print self.name, self.age ^ SyntaxError: invalid syntax
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
4 comments
I did the same with you.it worked well,but still don’t know what was wrong.
I tested and your code above is good, it passed no problem (yes: copy/paste)
nvm i figured it out it was an indentation error on the last print and 3 things above it…
thanks for your efforts