I Struggled with Coding Logic😱 Until I Did This!! 🫨

Akansha Yadav breaks down a five-step method for building coding logic: understand the problem, write pseudocode, translate to Python, debug with print statements, and practice 20 minutes daily. She walks through FizzBuzz to show how condition order matters, then modifies it to teach the framework's flexibility.
Chapters
So we are going to talk about something that every programmer needs and every beginner is struggling with, that is logic building. So logic building in this 2025 market is on hype. Everyone is talking about logic building because no one is able to ace it. Yes, so in this particular video, I will take you through a guide like what are the steps that you need to follow, why exactly we have to learn this, and what are the benefits. Everything we are going to learn with a realistic example. I am going to show you how these steps are going to benefit you for your programming or for your coding journey. So let's first understand what exactly logic building is. Whenever I say logic, you have to imagine it as a puzzle game. When it comes to the puzzle game, what we exactly have to do is we have to figure out certain pieces, we have to fit them together, and while fitting them together, what we are doing is we are solving a problem. Simple. In programming, we are going to apply some steps to solve any problem. It can be a complex problem or it can be a simple problem. But the thing that comes up is how do exactly we have to apply it in programming language. Everywhere around us we are experiencing logic building, but now the term is that why exactly we need logics in programming or in any problems that we are going to solve. Okay, so for this, just imagine that you are sitting in front of the computer and your task is that you have to calculate the total price of the item that is present in the cart. When the problem comes up in front of you, you might think that, okay, this is easy, this is pretty Simple, we can solve it. But there are certain scenarios, there are certain conditions that you need to add in your code. The scenarios can be like, what if the cart is empty? Or how do I handle the discounts that is being allotted to the individual person or individual profile? Or how do exactly— like, what if the customer is adding more product in the cart after I have calculated the total? So these are 3 scenarios that I have presented in front of you which will make your mind think rethink and rethink to come up with a perfect solution that fits this problem and can solve it effectively. Now, as I said that we are already experiencing logics around us. If I talk about day-to-day life, whenever we search on Google something, we are experiencing logics because whatever comes up in front of us is based on the query that I have passed to the browser. I wanted to automate a task, I can send automation like mail, sending emails, where I have certain conditions like at what time I do have to send, at, uh, to whom do exactly I have to send, and what is the body that I have to send. So there are certain scenarios, there are certain logics that is being applied everywhere, every task that we are doing day-to-day life. Whether you are using a calculator or whether you are playing a game, everywhere you are experiencing logic. And same logic we are going to learn how to apply it in any programming language when you wanted to solve any problem. Now there are 5 steps that you need to follow. When it comes to 5 steps, we will go step by step, but making sure that there are some key points that you need, need to note in each step. So make sure you are ready with your pen and paper or any Keynote thing from your laptop. Step number 1 is that you have to understand the problem. When you understand the problem effectively, before writing your Python code or before writing your programming languages or before starting your code, you have to first understand the problem. Once you can understand the problem, you can easily you know, easily write down your code. So your simple task is that you have to break your entire problem into small steps or into small subtasks. Now your main role will be to solve each subtask at one time, and eventually you are going to come up with a complete solution. Take an example that you have to calculate the sum of numbers from 1 to 100. This is the simple statement. This is the very classic problem. Which is in front of you. Now when I say that you have to understand the problem, then you have to reread the question and then you have to make some notes like, okay, first is that what is the starting number? Starting number is 1. Second is what is exactly the ending number? Ending number is 100. And third is what is the exact task that I am supposed to do? I am supposed to do the sum. Sum means addition of 1 2 3 up till 100. I have to do— this is the complete understanding of the problem statement and there is no certain scenarios that will come up in between. Now the second step is that you have to write down your Pseudocode. When it comes to pseudocode, pseudocode is nothing like— this is a very simple way of writing what exactly you are going to do in your code. This is going to be a simple English language sentences that you have to write about the problem and its solution. What do you think, how you are exactly going to solve it? Pseudocode is recommended by every programmer. Every companies want you to write down your pseudocode before you dive into the coding part. So write down a pseudocode, write down few English sentences that how exactly, what are the steps exactly you are going to follow. So for, let's say, uh, the task is— I'm just going to change one simple task that, okay, you have to calculate whether the number is even or odd. Simple. You have— when it comes to checking a number divisible by 2 and even numbers, and if number is not divisible by 2, it means it is odd number. So what are my steps that I am going to use to solve this problem? Is first thing is I need an input from the user of the number that exactly I have to check. Second is I am going to check whether that number is totally divisible by 2 and giving a remainder 0 or not. This is my step number 2. Step number 3 is I'm going to print one statement saying that this is an odd number. So there are mainly 3 steps that I'm going to follow, but in between I'm going to use which all— like, conditional statements that I'm going to use is I'm going to use if-else statement. So simple that I have written a pseudocode and I am pretty sure that for solving this entire problem I need these 2 things. I need one input and I need if-else statement, and I am good to go with others. Now I have already written a pseudocode. Now our step 3 is that you have to write down your Python code, or you have to write down your code exactly. Now at this stage you just have to convert your pseudocode into the Python code effectively with the correct syntax. At the stage of pseudocode, you don't have to worry about the syntaxes because this is just the English sentences that you have to write. But at the time of Python code or any programming code, you have to think about the syntax. You have to write it perfectly as you are writing the actual code. Now once you are going to run this, there comes a step number 4. Step number 4 says that you have to debug and experiment. If there is some error, if you are not getting the expected output, then you have to debug your entire code. When it comes to debugging then your task is that you have to basically add more print statement. Whenever you will add more print statement in your code, then you will be able to make it more effective and you will be able to analyze what is exactly happening at each step. Therefore, you can check where exactly the error is. So debugging is step number 4. Now the step number 5 is, which I recommend to every learner, is I recommend to every learner is that you have to practice, practice, practice. Once you are going to make it a habit, let's say you have a hectic schedule, then also you have to practice at least 20 minutes. I recommend that, okay, solve 1 problem, 2 problem, but invest 20 minutes a day to make it a habit. And eventually you will be able to see the changes in your thinking process and in the way that you are going to, you know, that you use to solve the problem. Now let's understand everything with a realistic example. I have taken one classic example which is FizzBuzz problem. FizzBuzz problem is often asked in the interviews to, you know, understand how you think, how you solve problems, and also this is very trendy and this is very common classic problem. So understand what exactly the challenge is. Our challenge is that we have to print numbers. We have to print numbers from 1 to 100, but there is a trick that you have to— there are some conditions like if the number is divisible by 3, you have to print fizz instead of that number. If the number is divisible by 5, you have to print buzz instead of the 5. And if the number is divisible by both, it means 3 and 5, then you have to print FizzBuzz. So these 3 conditions you have to add. So step number 1 is that you have to understand the problem effectively. Once you will understand the problem, then only you can solve it. When it comes to the understanding of the problem, then obviously we have to solve this problem, okay? We have to deal with the numbers, which is 1 to 100. We know the starting value, ending value, and we know that if I wanted to print entire list of numbers. I have to use loops for this purpose, and there are 3 conditions: is divisible by 3, is divisible by 5, and is divisible by both. Now, after understanding the problem, our step number 2 is we have to plan a pseudocode. When it comes to pseudocode, we have to write down certain English sentences, just like steps that we are going to follow in the code. Now, first thing is I'm going to use a loop. I'm going to loop through the numbers from 1 to 100. Second thing is I'm going to use if-else statement. I'm going to use conditional statements, and there are 3 conditions that I'm going to add. First is if it is— if the number is divisible by 3 and 5, then I'm going to print FizzBuzz. If the number is divisible by 3, I'm going to print Fizz. If the number is divisible by 5, I'm going to print Buzz. Now there is a twist in this. When I am writing the steps, just look at on my screen that I have written the divisibility by 2 first, like I have written it on the first priority, because there is the order of condition. The order of condition is very, very important in logic building. So if I— if let's say I'm not writing this condition first, if I'm just going to check whether the number is divisible by 3, it will print Fizz. But I want that if it is divisible by both, then it should print FizzBuzz. That is why I have changed the order of conditions, and I have made sure that, okay, first this condition will be checked. If it is divisible by both, it will print it. Otherwise, it will go to the next condition. It will say that, okay, out of these two conditions, I am checking first, first condition, which is divisibility by 3, and it is going to print the Fizz. And then for the 5 also, I'm going to do the same. But the order is very, very important. So the conditions for both 3 and 5 are very important. The order is important, which is super important in logic building, as I mentioned in my screen also. Now what our task is that we have to write down our code as per the steps that we have mentioned. We have to write down the code. On my screen you can see I'm using the for loop for the numbers in range 1 to 101 because we have to obviously increase one number out of it. Then I am writing the condition using the modulo operator and, and operator to add two conditions in single if statement. And then elif elif else is the entire code. Now what we have done exactly, we have converted our pseudocode into the actual Python code. Our step number 4 is we have to understand the logic, because as you are going to start writing your code using these steps, it is very important that you understand the logic that you have written. Now in this case which I have taken, I have written for loop and then I am using if elif and else. These 3 things I am primarily using to solve this problem, and I also made sure that I am using the correct order of the conditions. Now the come— next step is step number 5, which is to debug it. When you wanted to debug it, as I said, you have to add the print statement. So you can add it anywhere, wherever you want it to. So I have added one print statement to check which number exactly we are checking within if-else statement. Number 6 is that I recommend you practice with variation. There are so many questions that are available online, but not every question is tricky. They have made it pretty simple also. So that you guys can practice. But I recommend that from your knowledge, from your perspective, you made some variations in the question. Just like I have presented two of them, that you can replace multiples of 7 with boom and print Python for the numbers divisible by 2. So these two are the changes, these two are the variations. If you are going to implement it, you are going to experiment with more conditions, and eventually you will end up with a good logic building. So if you have found this video informative, don't forget to comment down and let me know what exactly you want me to cover in the next video. Bye-bye!










