Oh yes and welcome back to another class of course about so we talked about many things in this class
about Python and this class we are going to talk about a very important subject which are errors.
So basically in Python you have tried different types of errors that can exist and that can cure.
They're not very hard to understand and usually they're very simple to spot the first type of error
could be the syntax error.
In this case the syntax error is let's say for example you write down a point somewhere or whatever
so let's say you want to print something.
So let's say you print one divided by one.
So in the case you want to print this simple line of code as you can see it gives you one but let's
say you put a point in front of your print one divided by one.
You'll definitely have a syntax error.
So this is one type of errors.
The second type of error that you guys can deal with would be for example logical errors.
So in this case logical errors could be something like zero division import errors file but found errors.
So those are for example errors that happen if something is not logical so for example dividing one
by zero.
If you print it.
Well as you can see this is a logical error.
So is Zero Division is illogical error so this is the same type of errors that exist we have the all
the exceptions.
So this is also another type of errors but all the while all the exceptions that are in Python.
So basically deal the Zero Division error is also an exception.
Once again those are logical exceptions but you have different you have tens and tens of different error
types in Python.
Once again I'll show you where exactly we can fight them a bit later in this course.
So my goal today is to show you how you guys can deal with those type with the errors in general in
Python.
So instead of having a error signal right here and bugging all your program let's say you're programming
a more complex program what you can do is work with the try and accept functions.
So let me show you a quick example let's say you don't eat the basic line of code.
In this case we are going to ask a user to write down a certain number and this number well it could
be any type of number.
So we ask him to enter in number and that in this case we will simply print one plus number so will
our output will be one plus the number the number which is stored in the variable.
So if we decide to run our app what's going to happen we are going to ask a user to print a number to
give a number so let's say we give him 20 we'll have 21 in this case by then ask her the number right
here has to be a number.
So it's it has to be from.
Well just a number it could not be a string.
That is a let's say.
Letters it could not be letters in this case.
All right.
So what we'll do right now we'll do we'll enter letters and try to force and there.
So as you can see we enter letters we have and there is here once again this is a value here.
So right now how exactly can we deal with you with this type of errors it's very simple we'll use the
train except function so this way we'll be able to write something that is a bit more presentable than
this and we'll not block the our program to work.
So at first write don't try.
Then what exactly you want to try.
This is the code that you guys on the train.
So in this case we have our code and finally what do we accept.
So we accept to receive a value error.
In this case so let's say for example you accept to receive a certain type of errors or you think that
this error could be the most common error that you can receive.
Well simply write down that you accept this error.
And in this case what exactly you will sell you will say to your user you can simply say to him please
write a number so please write a number
so let's say we enter letters.
So as you can see the user will receive this message instead of receiving a huge message of error.
Usually you can if you want to make this a bit more cool let's say this way we can use it with a while
loop.
So this very basic app and what's going to happen is that it's going to refresh every time and the user
will try again again again and again and once again each time that he receives in there well it's will.
It will simply ask him again to print another number.
So as you can see there is something that is very very simple Your code will be between the track and
accept.
So let's say you want to try out a code or you want to receive a different outcome.
If for example you have in there you simply write it down here.
So let's say you try a certain line of code which write to you.
For example you have a certain line of code and that you guys accept a certain type of error that you
think that can cure.
For example the user with whom you work will enter letters instead of entering and number well you can
prevent this by simply using try and accept function.
So you guys understand right now how you can use this function.
It's not very hard to understand but it's again it can be very very useful.
So that's it for this class guys and see all our next class.