 Okay, welcome everybody. The number one question I get on my YouTube channel is why doesn't my code work? The answer to that question is I don't know. I Haven't seen your code. I don't know why it's not working, but Here is one of the most common types of errors that I see once people do share their code and do share the error message with me Indentation errors Python Indentation counts so that's called white space and it has to be aligned correctly for it to work So the first type of error we get is Called tab error inconsistent use of tabs and spaces in indentation. So I'm gonna go ahead and run this You'll see it tells you tab error inconsistent use of tabs and spaces in indentation. Oh my gosh It tells you the line number. Oh my gosh. It tells you the actual line So this is not a mystery and this is telling you exactly what the problem is So if I go and I look at this, I know this is a bit of a wide tab, but that's okay. It doesn't matter So I can see here I'm using the left arrow and the right arrow and my little cursor is moving left and right one space at a time So that tells me these are spaces if I go down a line 15 where the error is I push right it jumped Because this is a tab tabs spaces Okay, to fix this we just make it spaces Okay, and I run that again and There is the expected outputs so you cannot mix tabs and spaces that's that's indents a little bit too far doesn't need to be that far but Still the principle is the same again. I put this here This is a syntax error syntax error means the program doesn't even run You have done something against the Python rules the Python gods are not happy Python doesn't know what to do with your code. Let's take a look at number two This is another syntax error indentation Expected and indented blocks. Let me go ahead and run this Okay There's the error indentation error expected an indented block. There's the line number number 14 There's the line. Oh my gosh. It's all laid out for you So I'm gonna go take a look at line 14 and you can see here I've got a for loop and you've got a colon here at the end. That's a big clue What that tells me is the next line must be indented So now this line is inside the for loop This line is Outside the loop so inside a loop outside a loop inside a loop outside of loop I'm gonna keep it inside. I don't keep this outside of loop. So we go ahead and fix that And run it and we get the expected output Okay, moving on Number three the last one wasn't I'm gonna put it. How did I put it and you expected an indent and didn't get it and then in number three You got an indent, but you didn't expect it. So we go ahead and run this I've seen a pattern here Indentation error unexpected indent. There's the line number. There's a line Okay, so let's take a look at that Okay line 11. So I look at this statement and I look before it. There's no while loop. There's no for loop There's no if statement. There's no Defining of a function. So this should not be indented so we go ahead and Run it again And we're getting the expected output Okay, now those were syntax errors. So those are errors that Again, the program just doesn't run at all You've got to fix those before you can even run the program. The next two errors are what we call logic errors So in this case the program actually runs, but the output or it just doesn't do what you expected So for example in English if I say the bone ate the dog Grammatically, it's correct. It doesn't break any English rules of grammar. It just doesn't make sense That's not what we mean. Of course, we mean the dog ate the bone So same thing here In this program, I want the output to be exactly the same as it was for the other three programs But when I equals five, I want to print the word five Kind of great example fantastic stuff. So I'm gonna run it And you can see now it's not printing I Equals one or I equals two or I equals three Okay, the reason is that we over indented So this line here Should not be indented. It was accidentally indented. So that's causing a problem. So let's run that And now you can see I get the output that I expected I see this this a lot of times with with Viewers on my YouTube channel where they'll do something like this define move left There's a function and I'll have some code and then they'll put define move right And then I'll have some you know code here again Oops, I've got the colon and the problem is because this is indented It doesn't get registered into You know and this usually it's the global space that needs to be registered in at least in the basic tutorials I've been doing so this needs to be pulled over so that these are lined up correctly Generally speaking, you don't define something inside of something else or you don't find a function side of a function Generally speaking. Okay, so let me delete that and The last one is basically the opposite. So in this case, this was indented, but it shouldn't have been in the last case We're gonna have something that is Indented that shouldn't have been it's made the same case. Oh my gosh So let me go ahead and run this I'm gonna change that from 10 to 5 And I'm gonna go ahead and run See what happens. Okay, so you can see here We've got the end the end the end the end the end the end Again, that is clearly not what we wanted to happen So the reason that's happening is because this was indented and it shouldn't be so I'm gonna go ahead and run that and You can see now it functions as we want it. Okay Syntax errors are very very or should be very easy to figure out for the most part Again, you'll see an error message pretty pretty detailed. You'll see a line Usually the line It's pretty accurate. Okay, there are some there's some times when it isn't quite accurate. It's off by one or two That's probably for another video So you can't run the program at all And it basically tells you what the problem is where it is and which line it is Logic errors are a lot harder because you have to figure out. Oh my gosh. It's it's not doing what I want to do So what's happening and what isn't happening? What is happening? You have to look through the code and figure out where that problem is coming in again If you're not getting a syntax error Check your indentation a lot of times that is where the problem comes in. Okay, again, it's an art It's not necessarily a science. You do get a feel for these things and once you start coding a lot more you will Learn to debug your code a lot faster. So if you have these types of errors I hope this video is helpful to you. Good luck. Keep on coding subscribe for more. Thanks