1 00:00:00,740 --> 00:00:02,970 I've got some bad news for you. 2 00:00:02,970 --> 00:00:04,340 You aren't perfect. 3 00:00:04,340 --> 00:00:05,390 Nobody is. 4 00:00:05,390 --> 00:00:07,330 You're bound to make a mistake when you're coding. 5 00:00:07,330 --> 00:00:10,360 And even though we just agreed that making errors is a good thing. 6 00:00:10,360 --> 00:00:12,830 It can still feel a little overwhelming. 7 00:00:12,830 --> 00:00:16,980 Part of the reason for this is that you don't yet know the rules of the language. 8 00:00:16,980 --> 00:00:19,520 These rules are called syntax and 9 00:00:19,520 --> 00:00:23,070 I can pretty much guarantee you're going to make a syntax error. 10 00:00:23,070 --> 00:00:25,700 In fact it'd be super weird if you didn't. 11 00:00:25,700 --> 00:00:26,670 So let's do this. 12 00:00:26,670 --> 00:00:29,760 Let's force some errors and then walk through the fixes together. 13 00:00:29,760 --> 00:00:33,032 This error fixing skill will help assist you as you pick up the syntax of 14 00:00:33,032 --> 00:00:33,759 the language. 15 00:00:35,769 --> 00:00:39,060 Okay, so let's launch your workspace. 16 00:00:39,060 --> 00:00:42,750 So, remember when I said that case matters? 17 00:00:42,750 --> 00:00:47,660 So this function name here, print, let's capitalize that p. 18 00:00:50,069 --> 00:00:53,720 Now one nice thing that just happened, did you notice how the color changed? 19 00:00:53,720 --> 00:00:55,870 So see there's regular p, it's red. 20 00:00:55,870 --> 00:00:57,630 Here's capital P, blue. 21 00:00:58,640 --> 00:01:00,880 Our editor knows about the print function. 22 00:01:00,880 --> 00:01:05,770 Note, when I change the file there is a little orange dot up here. 23 00:01:05,770 --> 00:01:06,800 Do you see that? 24 00:01:06,800 --> 00:01:11,240 That's letting me know that the file has been edited, but not yet saved. 25 00:01:11,240 --> 00:01:14,180 So, what I'm gonna do, is I'm going to save this file. 26 00:01:14,180 --> 00:01:17,880 You come in here and you choose Save and you can see that I'm on a Mac so 27 00:01:17,880 --> 00:01:20,080 this is the sign for Cmd+S. 28 00:01:20,080 --> 00:01:22,890 So I believe on a Windows it's Ctrl+S. 29 00:01:22,890 --> 00:01:26,402 So you can go ahead and click Save and now you see the dot is gone. 30 00:01:26,402 --> 00:01:30,530 I wanna make you aware of this totally common problem. 31 00:01:30,530 --> 00:01:33,710 So you write amazing code and you forget to save it and 32 00:01:33,710 --> 00:01:37,280 then by pure instinct you just smack your face on the keyboard trying to figure out 33 00:01:37,280 --> 00:01:40,620 why your script isn't working the way that it says it's supposed to be working. 34 00:01:40,620 --> 00:01:42,340 And it's all because you forgot to save. 35 00:01:42,340 --> 00:01:45,180 And sometimes you even luck out and your nose hits the command key and 36 00:01:45,180 --> 00:01:48,450 your brow hits the S and you fix your problem, but that's rare. 37 00:01:48,450 --> 00:01:50,370 So mind the dot. 38 00:01:50,370 --> 00:01:54,910 So, since case matters, we know that lowercase print is different than this 39 00:01:54,910 --> 00:01:55,970 capital P print. 40 00:01:55,970 --> 00:01:57,430 But let's keep this here. 41 00:01:57,430 --> 00:01:59,440 Let's see what happens when we run it. 42 00:01:59,440 --> 00:02:02,750 So again, we're gonna come down here and we're gonna say Python. 43 00:02:02,750 --> 00:02:06,340 We're gonna call hello.py. 44 00:02:06,340 --> 00:02:08,180 Yikes, what's that? 45 00:02:08,180 --> 00:02:08,795 That's right. 46 00:02:08,795 --> 00:02:10,410 We've made this happen on purpose. 47 00:02:10,410 --> 00:02:13,450 So, this is what is known as a trace back and 48 00:02:13,450 --> 00:02:18,030 it helps you follow or trace the path in the code that caused the problem. 49 00:02:18,030 --> 00:02:20,900 Kinda makes you feel like a detective, right? 50 00:02:20,900 --> 00:02:23,270 Trace down that perpetrator. 51 00:02:23,270 --> 00:02:28,140 Now we only have a one line script, so it's pretty clear where the error is. 52 00:02:28,140 --> 00:02:30,150 But these can get pretty big pretty quick. 53 00:02:30,150 --> 00:02:35,231 So what this is saying is that the file hello.py on line one and 54 00:02:35,231 --> 00:02:39,920 if you look up here at these line numbers in the gutter. 55 00:02:39,920 --> 00:02:43,820 So if you come here, you can see that I can add new line numbers there and 56 00:02:43,820 --> 00:02:45,430 they go up, so that will help you find those. 57 00:02:45,430 --> 00:02:46,888 I'm gonna get rid of those. 58 00:02:46,888 --> 00:02:49,064 So, we've got an error in line one, and 59 00:02:49,064 --> 00:02:52,140 if you come down to the very bottom you'll see the error. 60 00:02:52,140 --> 00:02:54,580 And we have a name error. 61 00:02:54,580 --> 00:03:01,670 And here it says the name Print with the capital P you notice, is not defined. 62 00:03:01,670 --> 00:03:06,773 So, name here is the name of the function print. 63 00:03:06,773 --> 00:03:10,020 We'll learn here in a bit how to define our own names. 64 00:03:10,020 --> 00:03:13,840 Basically the interpreter here is saying, what you talking about? 65 00:03:13,840 --> 00:03:17,285 There isn't anything defined as a capital P print. 66 00:03:17,285 --> 00:03:18,570 Remember, case matters. 67 00:03:18,570 --> 00:03:21,920 Capital P print and lower case print are different. 68 00:03:21,920 --> 00:03:24,180 Different key strokes for different folks. 69 00:03:24,180 --> 00:03:28,650 So let's fix this, let's go ahead, come up here, change this back to lower case p. 70 00:03:29,770 --> 00:03:31,458 There we go, back to red. 71 00:03:31,458 --> 00:03:38,710 All right, so this print function here is called, I briefly explained earlier that 72 00:03:38,710 --> 00:03:44,470 you call a function by providing an open parentheses and a closing parentheses. 73 00:03:44,470 --> 00:03:48,330 Now note here, if I put my cursor at the opening parentheses or 74 00:03:48,330 --> 00:03:50,400 the closing parentheses, it will highlight. 75 00:03:50,400 --> 00:03:52,700 It will show me how they're balanced. 76 00:03:52,700 --> 00:03:56,850 And it is important that they're balanced, it's part of the syntax of the language. 77 00:03:56,850 --> 00:04:01,590 The syntax states that for a function that an opening parentheses and 78 00:04:01,590 --> 00:04:06,930 everything in between it and the closing parenthesis are arguments. 79 00:04:06,930 --> 00:04:11,540 So, what happens if we forget the trailing parenthesis? 80 00:04:11,540 --> 00:04:14,420 Let's go ahead and get rid of that. 81 00:04:14,420 --> 00:04:16,020 This is invalid syntax, right? 82 00:04:16,020 --> 00:04:18,366 Where would the function call actually end now? 83 00:04:18,366 --> 00:04:20,410 It doesn't, right? 84 00:04:20,410 --> 00:04:22,250 So I'm gonna go ahead, I'm gonna save this. 85 00:04:22,250 --> 00:04:25,261 See the red dot, now the red dot's gone. 86 00:04:25,261 --> 00:04:28,000 So I'm gonna come down back to my terminal. 87 00:04:28,000 --> 00:04:31,400 And the terminal actually has history as well and I can use the up arrow, 88 00:04:31,400 --> 00:04:33,725 and we'll run python hello.py. 89 00:04:33,725 --> 00:04:39,006 File hello.py line 2, what, there's only one line. 90 00:04:39,006 --> 00:04:42,777 So we have here a syntax error, 91 00:04:42,777 --> 00:04:47,180 unexpected EOF while parsing. 92 00:04:47,180 --> 00:04:49,969 Now parsing is the way that the interpreter breaks down what you wrote 93 00:04:49,969 --> 00:04:51,521 into something that it understands. 94 00:04:51,521 --> 00:04:56,102 It had a problem understanding us because we didn't follow the rules of 95 00:04:56,102 --> 00:04:57,104 the language. 96 00:04:57,104 --> 00:05:02,400 Now, if you don't know what EOF means and you probably don't, what would you do? 97 00:05:03,560 --> 00:05:08,190 Well, what do you do these days when you don't know what a term means. 98 00:05:08,190 --> 00:05:08,700 What do you do? 99 00:05:09,715 --> 00:05:10,485 Yeah, that's right. 100 00:05:10,485 --> 00:05:15,175 You just ask Google or you ask Alexa, or whoever your preferred oracle is. 101 00:05:15,175 --> 00:05:17,195 Let's go over there, I'm gonna use Google for right now. 102 00:05:17,195 --> 00:05:18,295 Hi Maya. 103 00:05:18,295 --> 00:05:22,065 So, I'll say what does EOF stand for? 104 00:05:24,285 --> 00:05:27,823 In computing, end-of-file, commonly abbreviated EOF, is a condition and 105 00:05:27,823 --> 00:05:31,358 a computer operating system where no more data can be read from the data source, 106 00:05:31,358 --> 00:05:32,200 end-of-file. 107 00:05:32,200 --> 00:05:33,990 Well, that makes sense, 108 00:05:33,990 --> 00:05:38,710 it reached the end of the file without finding the closing paren. 109 00:05:38,710 --> 00:05:41,940 I want to reiterate here that you are never alone in your errors. 110 00:05:41,940 --> 00:05:44,740 Millions of people are coding and making mistakes. 111 00:05:44,740 --> 00:05:47,470 You'll find answers to their questions if you just search for them. 112 00:05:47,470 --> 00:05:49,890 The internet is pretty amazing, isn't it? 113 00:05:49,890 --> 00:05:51,760 Now, for course specific things, 114 00:05:51,760 --> 00:05:54,390 remember that there's a wonderful community here to ask. 115 00:05:54,390 --> 00:05:57,840 And you can also search the archives on questions and answers. 116 00:05:57,840 --> 00:06:02,580 So let me point out one more common gotcha before we get cooking. 117 00:06:02,580 --> 00:06:05,810 This is one that happens all the time. 118 00:06:05,810 --> 00:06:11,451 So, in Python you can make a string just like we did here with double quotes, 119 00:06:11,451 --> 00:06:15,506 or you could also use, I'm gonna put this paren back, 120 00:06:15,506 --> 00:06:18,088 you could also use single quotes. 121 00:06:18,088 --> 00:06:22,060 So this is also valid, single quotes. 122 00:06:22,060 --> 00:06:26,280 It really is just a question of style, often though, 123 00:06:26,280 --> 00:06:29,710 the error that happens is that there is a mismatch. 124 00:06:29,710 --> 00:06:32,670 One single quote and one double quote. 125 00:06:32,670 --> 00:06:36,120 Now let's do that, one single quote, and we'll trail it with a double quote. 126 00:06:36,120 --> 00:06:39,480 Now a careful look at that closing paren will show you the problem. 127 00:06:39,480 --> 00:06:43,620 Notice how when it's correct it's black, and 128 00:06:43,620 --> 00:06:48,390 when it's not it's that teal color, the same color as our string. 129 00:06:48,390 --> 00:06:51,690 Now, that's because the string hasn't been ended yet. 130 00:06:51,690 --> 00:06:55,600 It's waiting for us to finish with a single quote, and 131 00:06:55,600 --> 00:06:59,687 it's totally fine to have a quote and a paren in a string. 132 00:06:59,687 --> 00:07:03,130 So there if I put that in, that's valid right? 133 00:07:03,130 --> 00:07:05,740 But since there is no closing single quote, 134 00:07:05,740 --> 00:07:08,460 they're part of the unclosed string. 135 00:07:08,460 --> 00:07:10,420 So let's go ahead, let's make our error happen. 136 00:07:10,420 --> 00:07:11,420 I'm gonna save this. 137 00:07:13,957 --> 00:07:18,457 And I am gonna type clear down here because that will clear the console stuff 138 00:07:18,457 --> 00:07:22,041 that's there and I will press up and get python hello.py. 139 00:07:24,182 --> 00:07:29,768 Here we go, we got a syntax error and we have EOL which is end of line, 140 00:07:29,768 --> 00:07:33,680 while scanning the string literal. 141 00:07:33,680 --> 00:07:37,430 And you can see that there is an arrow here actually pointing 142 00:07:37,430 --> 00:07:39,800 to where it expected the ending of the string. 143 00:07:39,800 --> 00:07:43,480 Now, this is where you want to really inspect closely, 144 00:07:43,480 --> 00:07:45,600 almost character by character. 145 00:07:45,600 --> 00:07:49,580 I want you to hone your inner detective, aha, 146 00:07:49,580 --> 00:07:52,690 elementary dear Watson, mismatched quotes. 147 00:07:54,140 --> 00:07:55,970 I hope you now feel a little more prepared for 148 00:07:55,970 --> 00:07:59,160 when you encounter those errors and you will. 149 00:07:59,160 --> 00:08:00,500 Don't let them get you down. 150 00:08:00,500 --> 00:08:04,953 When you see those tracebacks, try to remind yourself hey, look at me, 151 00:08:04,953 --> 00:08:05,975 I'm learning. 152 00:08:05,975 --> 00:08:09,346 And with that confidence, let's get to writing some code. 153 00:08:09,346 --> 00:08:11,350 That is right after you take a quick break. 154 00:08:11,350 --> 00:08:13,610 Taking breaks is super important for your learning. 155 00:08:13,610 --> 00:08:14,390 You'll thank me later. 156 00:08:14,390 --> 00:08:17,040 A lot of information just went into your brain. 157 00:08:17,040 --> 00:08:18,340 Let it sink in. 158 00:08:18,340 --> 00:08:21,810 Give a nice stretch, grab a snack, pet your cat, water your plants, 159 00:08:21,810 --> 00:08:25,110 refill your coffee or whatever it is that you like to do when you're taking a break. 160 00:08:25,110 --> 00:08:27,040 It doesn't have to be long. 161 00:08:27,040 --> 00:08:28,190 Come back refreshed and 162 00:08:28,190 --> 00:08:31,180 ready to name some things cuz that's whats up next, creating variables.