Debugging

As you have done more and more coding, you have probably realized how easy it is to make errors and how hard it is to find and fix them. As you are going through and trying to find and fix your code, know that there is always a solution to whatever you are trying to do and if you try hard enough, you will be able to find it. A lot of times, it's something simple that you probably just overlooked.
Programming has a steep learning curve, so don't feel discouraged if you feel confident at one point and then feel like you don't know anything the next second. Trust me, every developer has felt like they knew how to do everything, then got stuck on one thing and then couldn't figure out how to do anything after. Like any other skill, becoming a good programmer requires A LOT of practice, many tears, and a immense amount of motivation and grit. If you put in the effort, one day you will start to see the results!

There is also a very famous meme that exists in the developer community called Tutorial Hell. Basically it is saying that if you watch too many tutorials, you will become reliant on them and won't know how to write programs yourself and troubleshoot them when things inevitably go wrong. Whatever you do, make sure you do not fall into tutorial hell!!! Make projects your main source of learning, pick something to do and figure out how to do it. Don't just follow a YouTube tutorial for everything.

Print Statements
If you are every having a hard time trying to find where the bug in your code is, try using print statements throughout your code. Sometimes, the problem is that something unexpected is happening to your variables or a loop is not being entered or something of the sort. You can just have print statements throughout your code printing different variables or printing something when a loop is entered. This way, you will know what parts of your code work and what is happening to different aspects of the program during runtime. Knowing what is working well can help you narrow down what is not working well.
Debug Console
A lot of conde editors will come with built-in debug consoles. This can help you see everything that happens during runtime, like seeing what variables are created, what their values are at every line of the program, and see how they change. It can also help you see which loops are being entered and how different conditionals are evaluated, which may help you figure out where the problem in your code is. The debug console also comes with a breakpoint feature, where you can stop the program at any point in time to see what different logistics of the code look like at that instant. This is helpful if your program has a lot of code and you don't want to sit there and watch it go through parts of the code that you already know work well. Here are some good videos that explain how to use the console:
Testing
Many times, code issues arise from the computer not knowing what to do with different types of input. Or, you might have a sitation where some input works, but other inputs throw an error. In cases like this, just use trial and error to try different inputs(however, this only works for programs that take user input), and see what is causing the problem. Maybe you need another conditional to catch input that you did not initially plan for. Or maybe you didn't clean the input properly.
Find and Fix the Bug
Below is a program with a couple of bug in it. You need to find the bugs and comment on them(put a hashtag in front of what you write, the computer will completely
read over it so you won't get any errors), explaining what they did wrong. Then try to fix the error.
Hint: there are two syntax errors and one logic error.
nums = [1, 2, 3, 4, 5]
for i in nums
sum = 0
sum = sum + i
if(sum == 3):
print hello
print(sum)
This is what the output should look like when all the errors are fixed:
