1 00:00:07,940 --> 00:00:12,135 The first error is called the syntax error. 2 00:00:12,135 --> 00:00:17,490 Just like in English where we have syntax as an important part of grammar, 3 00:00:17,490 --> 00:00:22,545 a syntax error in Python means that the statements just aren't well formed, 4 00:00:22,545 --> 00:00:25,650 the interpreter can't parse it. 5 00:00:25,650 --> 00:00:29,190 In this case, we have the word print and we have 6 00:00:29,190 --> 00:00:33,075 the open parenthesis and then something to print 7 00:00:33,075 --> 00:00:36,540 but we're missing the closing parentheses and 8 00:00:36,540 --> 00:00:41,100 the Python interpreter tries to keep looking further on, 9 00:00:41,100 --> 00:00:44,780 as well there's no closed parentheses here but 10 00:00:44,780 --> 00:00:48,680 maybe it'll be here or down here and it keeps going to look for it, 11 00:00:48,680 --> 00:00:51,965 it can't find it and it just says, "This is an error." 12 00:00:51,965 --> 00:00:54,200 I don't know what the programmer had in mind here. 13 00:00:54,200 --> 00:00:55,630 Doesn't try to guess. 14 00:00:55,630 --> 00:00:57,605 It says, "This is a syntax error." 15 00:00:57,605 --> 00:01:00,370 So, let's see what that looks like. 16 00:01:00,370 --> 00:01:03,410 We actually get an error message and it tells us, 17 00:01:03,410 --> 00:01:09,035 syntax error and then it tells us something about what's going on and it says, "EOF." 18 00:01:09,035 --> 00:01:13,090 That's an acronym EOF end of file. 19 00:01:13,090 --> 00:01:14,750 Of course we don't really have a file, 20 00:01:14,750 --> 00:01:18,770 we just have a little window but it thinks of the contents of 21 00:01:18,770 --> 00:01:23,020 that window as being a file that has commands in it, 22 00:01:23,020 --> 00:01:25,970 it got to the end of that file it 23 00:01:25,970 --> 00:01:29,030 was in the middle of a multi-line statement the statement started on line 24 00:01:29,030 --> 00:01:32,210 one and it was waiting for that statement to end with 25 00:01:32,210 --> 00:01:35,975 that close parentheses and it never got to the end, 26 00:01:35,975 --> 00:01:37,900 you got to line three, 27 00:01:37,900 --> 00:01:42,859 the end of the file without ever seeing a closed parenthesis. 28 00:01:42,859 --> 00:01:47,394 Now, in the textbook when you're executing Python, 29 00:01:47,394 --> 00:01:52,540 we've actually tried to translate some of the error messages that you would 30 00:01:52,540 --> 00:01:54,985 get in a normal python interpreter and make them 31 00:01:54,985 --> 00:01:58,355 easier to understand for someone who is just getting started programming. 32 00:01:58,355 --> 00:02:01,600 So, believe it or not this is actually already a little 33 00:02:01,600 --> 00:02:05,170 bit more human-friendly than you might get normally, 34 00:02:05,170 --> 00:02:08,020 and we've tried to give you a little description and 35 00:02:08,020 --> 00:02:10,985 some suggestions of what you should do to fix it. 36 00:02:10,985 --> 00:02:14,875 In this case the things that are suggesting aren't quite what we need, 37 00:02:14,875 --> 00:02:18,160 what we really needed was 38 00:02:18,160 --> 00:02:24,705 a close parenthesis The other thing to notice here is that it's telling us line three, 39 00:02:24,705 --> 00:02:29,045 there isn't even a line three but certainly the place where we ought to 40 00:02:29,045 --> 00:02:33,640 add the parenthesis is on line one not on line three, 41 00:02:33,640 --> 00:02:35,990 is just that the problem started on line 42 00:02:35,990 --> 00:02:38,510 one and the interpreter wasn't really sure it was 43 00:02:38,510 --> 00:02:40,820 a problem until it got to the end of 44 00:02:40,820 --> 00:02:44,820 the file line three without getting the close parenthesis. 45 00:02:46,160 --> 00:02:49,650 So, if I put this here, 46 00:02:49,650 --> 00:02:52,480 now it will run just fine. 47 00:02:53,600 --> 00:03:03,135 An alternative, I could have put it here and that also would be fine. 48 00:03:03,135 --> 00:03:06,040 Normally, there would be no reason to do that, 49 00:03:06,040 --> 00:03:08,950 it would be much easier to read if you put it there. 50 00:03:08,950 --> 00:03:11,855 Now here I'm going to get another error. 51 00:03:11,855 --> 00:03:17,900 It says a bad input on line three because I have this extra close parenthesis, 52 00:03:17,900 --> 00:03:21,820 and these are all syntax errors that make it impossible for 53 00:03:21,820 --> 00:03:26,240 the interpreter to figure out what the program was supposed to do. 54 00:03:26,240 --> 00:03:30,115 The second type of error are runtime errors. 55 00:03:30,115 --> 00:03:34,435 These occur when the interpreter is able to parse the program, 56 00:03:34,435 --> 00:03:38,560 but during the running of the program some illegal operation happens. 57 00:03:38,560 --> 00:03:42,260 For example, let me do one of those. 58 00:03:42,260 --> 00:03:46,520 Suppose I print three divided by zero. 59 00:03:46,520 --> 00:03:49,470 What is three divided by zero? 60 00:03:49,470 --> 00:03:51,850 Infinity maybe. 61 00:03:52,130 --> 00:03:58,285 It's not illegal operation doesn't make sense to divide by zero and if I try to do that, 62 00:03:58,285 --> 00:04:02,585 I get this zero division error where it says, 63 00:04:02,585 --> 00:04:06,505 the integer division or modulo by zero on line one. 64 00:04:06,505 --> 00:04:09,120 So, that's an example of a runtime error. 65 00:04:09,120 --> 00:04:14,540 It can figure out what you're trying to do but it's not a legal operation. 66 00:04:14,540 --> 00:04:18,105 The third type of error is called the semantic error. 67 00:04:18,105 --> 00:04:23,695 That's when the Python interpreter is able to parse the code, 68 00:04:23,695 --> 00:04:26,110 it's actually able to run it but it doesn't 69 00:04:26,110 --> 00:04:29,080 produce the thing that the programmer intended. 70 00:04:29,080 --> 00:04:35,120 So for example, suppose I try to print something that 71 00:04:35,120 --> 00:04:40,880 explains the conversion of a fraction to a percentage but I do it a little bit wrong. 72 00:04:40,880 --> 00:04:44,990 So, I say 1.5 as a percentage 73 00:04:44,990 --> 00:04:53,160 is and then I say one over two. 74 00:04:54,770 --> 00:05:02,260 I'd like it to say 50 percent but it's really going to say 0.5. 75 00:05:04,160 --> 00:05:10,915 What I should've done here is multiply it by a 100 to turn it into a percentage. 76 00:05:10,915 --> 00:05:15,490 So, 1.5 is a percentage is 50 percent. 77 00:05:16,300 --> 00:05:21,620 I apologize for the line break there but you can figure out what it means, 50 percent. 78 00:05:21,620 --> 00:05:23,900 So, when I left off the 100 and I just 79 00:05:23,900 --> 00:05:33,475 said one over two that was a semantic error, 80 00:05:33,475 --> 00:05:35,750 was a programmer's error that produced 81 00:05:35,750 --> 00:05:39,380 the wrong thing but the program was able to run all the way to completion, 82 00:05:39,380 --> 00:05:42,690 it just didn't do what I wanted it to do. 83 00:05:42,700 --> 00:05:49,895 So, those are our three types of errors syntax, runtime and semantic. 84 00:05:49,895 --> 00:05:54,170 In this multiple choice question which you'll get a version of 85 00:05:54,170 --> 00:05:58,690 an each of the pages for the three different error types we've got one example of each. 86 00:05:58,690 --> 00:06:01,110 So, attempting to divide by zero, 87 00:06:01,110 --> 00:06:04,090 that is a runtime error. 88 00:06:09,200 --> 00:06:14,599 Forgetting a semicolon at the end of a statement where one is required, 89 00:06:14,599 --> 00:06:17,915 that would make it impossible to parse what you've written 90 00:06:17,915 --> 00:06:22,900 and that would be a syntax error. 91 00:06:24,380 --> 00:06:27,680 If you forget to divide by a 100 or 92 00:06:27,680 --> 00:06:30,650 multiplied by a 100 when you're printing a percentage amount, 93 00:06:30,650 --> 00:06:34,660 that would be a semantic error.