The following Python code is meant to output the first 10 positive perfect squares .
What will happen when the code is executed?
1 2 |
|
Note:
You are not allowed to run the code using a Python interpreter!
Note: The syntax highlighting is off on purpose!
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The variable i will loop from 0 to 9. Since the desired output is the first 10 positive squares, and we are including 0, the output will not be what we intend. This logical issue is called a semantic error.
In contrast, a syntax error is an issue with the language (for example, forgetting the : after the for statement) and is typically caught by your IDE before the program even begins. A runtime error is any uncaught error that happens at runtime. A common example might be a divide by zero error.