The first error is called the syntax error.
Just like in English where we have syntax as an important part of grammar,
a syntax error in Python means that the statements just aren't well formed,
the interpreter can't parse it.
In this case, we have the word print and we have
the open parenthesis and then something to print
but we're missing the closing parentheses and
the Python interpreter tries to keep looking further on,
as well there's no closed parentheses here but
maybe it'll be here or down here and it keeps going to look for it,
it can't find it and it just says, "This is an error."
I don't know what the programmer had in mind here.
Doesn't try to guess.
It says, "This is a syntax error."
So, let's see what that looks like.
We actually get an error message and it tells us,
syntax error and then it tells us something about what's going on and it says, "EOF."
That's an acronym EOF end of file.
Of course we don't really have a file,
we just have a little window but it thinks of the contents of
that window as being a file that has commands in it,
it got to the end of that file it
was in the middle of a multi-line statement the statement started on line
one and it was waiting for that statement to end with
that close parentheses and it never got to the end,
you got to line three,
the end of the file without ever seeing a closed parenthesis.
Now, in the textbook when you're executing Python,
we've actually tried to translate some of the error messages that you would
get in a normal python interpreter and make them
easier to understand for someone who is just getting started programming.
So, believe it or not this is actually already a little
bit more human-friendly than you might get normally,
and we've tried to give you a little description and
some suggestions of what you should do to fix it.
In this case the things that are suggesting aren't quite what we need,
what we really needed was
a close parenthesis The other thing to notice here is that it's telling us line three,
there isn't even a line three but certainly the place where we ought to
add the parenthesis is on line one not on line three,
is just that the problem started on line
one and the interpreter wasn't really sure it was
a problem until it got to the end of
the file line three without getting the close parenthesis.
So, if I put this here,
now it will run just fine.
An alternative, I could have put it here and that also would be fine.
Normally, there would be no reason to do that,
it would be much easier to read if you put it there.
Now here I'm going to get another error.
It says a bad input on line three because I have this extra close parenthesis,
and these are all syntax errors that make it impossible for
the interpreter to figure out what the program was supposed to do.
The second type of error are runtime errors.
These occur when the interpreter is able to parse the program,
but during the running of the program some illegal operation happens.
For example, let me do one of those.
Suppose I print three divided by zero.
What is three divided by zero?
Infinity maybe.
It's not illegal operation doesn't make sense to divide by zero and if I try to do that,
I get this zero division error where it says,
the integer division or modulo by zero on line one.
So, that's an example of a runtime error.
It can figure out what you're trying to do but it's not a legal operation.
The third type of error is called the semantic error.
That's when the Python interpreter is able to parse the code,
it's actually able to run it but it doesn't
produce the thing that the programmer intended.
So for example, suppose I try to print something that
explains the conversion of a fraction to a percentage but I do it a little bit wrong.
So, I say 1.5 as a percentage
is and then I say one over two.
I'd like it to say 50 percent but it's really going to say 0.5.
What I should've done here is multiply it by a 100 to turn it into a percentage.
So, 1.5 is a percentage is 50 percent.
I apologize for the line break there but you can figure out what it means, 50 percent.
So, when I left off the 100 and I just
said one over two that was a semantic error,
was a programmer's error that produced
the wrong thing but the program was able to run all the way to completion,
it just didn't do what I wanted it to do.
So, those are our three types of errors syntax, runtime and semantic.
In this multiple choice question which you'll get a version of
an each of the pages for the three different error types we've got one example of each.
So, attempting to divide by zero,
that is a runtime error.
Forgetting a semicolon at the end of a statement where one is required,
that would make it impossible to parse what you've written
and that would be a syntax error.
If you forget to divide by a 100 or
multiplied by a 100 when you're printing a percentage amount,
that would be a semantic error.