1/14 Why the semicolon?


#1


https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/0/1?curriculum_id=4f89dab3d788890003000096

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]


#2

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


#3

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.


#4

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?


#5


#6

Exactly what is demonstrated, following:

 > print "a"; print "b"; print "c"
 a
 b
 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.


#7

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