1/14 Why the semicolon?



I would have expected an error to occur on line 1 with the semicolon on the end.

Why include an unnecessary semicolon in a training example and then not even mention it?

zoo_animals = ["pangolin", "cassowary", "sloth", "Human"];
# One animal is missing!

if len(zoo_animals) > 3:
	print "The first animal at the zoo is the " + zoo_animals[0]
	print "The second animal at the zoo is the " + zoo_animals[1]
	print "The third animal at the zoo is the " + zoo_animals[2]
	print "The fourth animal at the zoo is the " + zoo_animals[3]


its not really needed but if you wanted to write another statement on that same line then you would need it


after researching through google, I came to that same conclusion. I am confused now, more by WHY codeacademy would throw what would be considered bad code form into this early of a lesson without even addressing it. Perhaps you as a mod could let them know about this.


Looked through the lesson and there is no semicolon in the default code given perhaps can you reset the code you have and take a snapshot of the page with the semicolon?



Exactly what is demonstrated, following:

 > print "a"; print "b"; print "c"
 > print "a" print "b" print "c"
  File "<stdin>", line 1
    print "a" print "b" print "c"
SyntaxError: invalid syntax
Unknown error.

It is so non-standard to write compressed code in Python that this option rarely if ever comes up. Interesting that it would only now come to light, being as the course is over three years old. The things we are still discovering. At least we know that it is not a bug, even if it was accidentally (perhaps) included.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.