1 00:00:00,390 --> 00:00:07,790 Oh yes and welcome back to another class of course about so we talked about many things in this class 2 00:00:07,880 --> 00:00:14,750 about Python and this class we are going to talk about a very important subject which are errors. 3 00:00:14,750 --> 00:00:21,390 So basically in Python you have tried different types of errors that can exist and that can cure. 4 00:00:21,710 --> 00:00:26,750 They're not very hard to understand and usually they're very simple to spot the first type of error 5 00:00:26,780 --> 00:00:29,420 could be the syntax error. 6 00:00:29,720 --> 00:00:34,730 In this case the syntax error is let's say for example you write down a point somewhere or whatever 7 00:00:34,730 --> 00:00:36,710 so let's say you want to print something. 8 00:00:36,710 --> 00:00:39,080 So let's say you print one divided by one. 9 00:00:39,710 --> 00:00:43,490 So in the case you want to print this simple line of code as you can see it gives you one but let's 10 00:00:43,490 --> 00:00:47,090 say you put a point in front of your print one divided by one. 11 00:00:47,270 --> 00:00:49,840 You'll definitely have a syntax error. 12 00:00:50,090 --> 00:00:52,340 So this is one type of errors. 13 00:00:52,670 --> 00:00:57,910 The second type of error that you guys can deal with would be for example logical errors. 14 00:00:57,920 --> 00:01:05,020 So in this case logical errors could be something like zero division import errors file but found errors. 15 00:01:05,060 --> 00:01:12,080 So those are for example errors that happen if something is not logical so for example dividing one 16 00:01:12,080 --> 00:01:12,590 by zero. 17 00:01:12,590 --> 00:01:13,490 If you print it. 18 00:01:13,710 --> 00:01:16,970 Well as you can see this is a logical error. 19 00:01:17,030 --> 00:01:28,430 So is Zero Division is illogical error so this is the same type of errors that exist we have the all 20 00:01:28,430 --> 00:01:29,350 the exceptions. 21 00:01:29,360 --> 00:01:36,910 So this is also another type of errors but all the while all the exceptions that are in Python. 22 00:01:36,980 --> 00:01:41,120 So basically deal the Zero Division error is also an exception. 23 00:01:41,120 --> 00:01:48,710 Once again those are logical exceptions but you have different you have tens and tens of different error 24 00:01:48,710 --> 00:01:50,220 types in Python. 25 00:01:50,560 --> 00:01:54,000 Once again I'll show you where exactly we can fight them a bit later in this course. 26 00:01:54,020 --> 00:01:59,870 So my goal today is to show you how you guys can deal with those type with the errors in general in 27 00:01:59,870 --> 00:02:00,480 Python. 28 00:02:00,560 --> 00:02:06,170 So instead of having a error signal right here and bugging all your program let's say you're programming 29 00:02:06,260 --> 00:02:13,060 a more complex program what you can do is work with the try and accept functions. 30 00:02:13,080 --> 00:02:17,330 So let me show you a quick example let's say you don't eat the basic line of code. 31 00:02:17,480 --> 00:02:23,690 In this case we are going to ask a user to write down a certain number and this number well it could 32 00:02:23,690 --> 00:02:26,870 be any type of number. 33 00:02:26,960 --> 00:02:34,790 So we ask him to enter in number and that in this case we will simply print one plus number so will 34 00:02:34,880 --> 00:02:40,130 our output will be one plus the number the number which is stored in the variable. 35 00:02:40,850 --> 00:02:49,460 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 36 00:02:49,640 --> 00:02:55,700 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 37 00:02:55,700 --> 00:02:57,890 here has to be a number. 38 00:02:57,890 --> 00:03:00,520 So it's it has to be from. 39 00:03:00,740 --> 00:03:03,670 Well just a number it could not be a string. 40 00:03:03,860 --> 00:03:04,980 That is a let's say. 41 00:03:04,980 --> 00:03:08,280 Letters it could not be letters in this case. 42 00:03:08,280 --> 00:03:08,580 All right. 43 00:03:08,580 --> 00:03:16,410 So what we'll do right now we'll do we'll enter letters and try to force and there. 44 00:03:16,410 --> 00:03:21,690 So as you can see we enter letters we have and there is here once again this is a value here. 45 00:03:21,730 --> 00:03:28,180 So right now how exactly can we deal with you with this type of errors it's very simple we'll use the 46 00:03:28,190 --> 00:03:34,660 train except function so this way we'll be able to write something that is a bit more presentable than 47 00:03:34,660 --> 00:03:41,050 this and we'll not block the our program to work. 48 00:03:41,080 --> 00:03:43,630 So at first write don't try. 49 00:03:43,930 --> 00:03:45,700 Then what exactly you want to try. 50 00:03:45,700 --> 00:03:47,440 This is the code that you guys on the train. 51 00:03:47,960 --> 00:03:52,790 So in this case we have our code and finally what do we accept. 52 00:03:54,020 --> 00:03:58,750 So we accept to receive a value error. 53 00:03:58,850 --> 00:04:03,890 In this case so let's say for example you accept to receive a certain type of errors or you think that 54 00:04:03,890 --> 00:04:06,780 this error could be the most common error that you can receive. 55 00:04:07,550 --> 00:04:09,820 Well simply write down that you accept this error. 56 00:04:10,340 --> 00:04:20,480 And in this case what exactly you will sell you will say to your user you can simply say to him please 57 00:04:22,540 --> 00:04:27,770 write a number so please write a number 58 00:04:31,670 --> 00:04:34,230 so let's say we enter letters. 59 00:04:34,230 --> 00:04:40,360 So as you can see the user will receive this message instead of receiving a huge message of error. 60 00:04:40,360 --> 00:04:47,260 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 61 00:04:47,260 --> 00:04:48,250 loop. 62 00:04:49,300 --> 00:04:54,250 So this very basic app and what's going to happen is that it's going to refresh every time and the user 63 00:04:54,250 --> 00:05:00,900 will try again again again and again and once again each time that he receives in there well it's will. 64 00:05:00,890 --> 00:05:04,730 It will simply ask him again to print another number. 65 00:05:04,930 --> 00:05:09,200 So as you can see there is something that is very very simple Your code will be between the track and 66 00:05:09,220 --> 00:05:09,630 accept. 67 00:05:09,640 --> 00:05:13,430 So let's say you want to try out a code or you want to receive a different outcome. 68 00:05:13,450 --> 00:05:17,080 If for example you have in there you simply write it down here. 69 00:05:17,080 --> 00:05:21,190 So let's say you try a certain line of code which write to you. 70 00:05:21,190 --> 00:05:26,500 For example you have a certain line of code and that you guys accept a certain type of error that you 71 00:05:26,500 --> 00:05:27,700 think that can cure. 72 00:05:27,700 --> 00:05:34,900 For example the user with whom you work will enter letters instead of entering and number well you can 73 00:05:35,350 --> 00:05:38,440 prevent this by simply using try and accept function. 74 00:05:39,070 --> 00:05:42,250 So you guys understand right now how you can use this function. 75 00:05:42,250 --> 00:05:45,610 It's not very hard to understand but it's again it can be very very useful. 76 00:05:45,660 --> 00:05:48,910 So that's it for this class guys and see all our next class.