So you learned python, picked one of the best tutorials online, and aced through it. You loved Python and decided it was the one. But you ended up feeling completely lost when you tried to do your own project. It feels as if you have learned nothing.
You wonder if those hours you have spent on learning the language is utter waste, that you missed something. You are urged to start from the beginning again in hopes of finding something new, only to end up with the same old variables, data structures, and loops.
You switch to other online resources, books that teach Python, but the result are the same. The next resort is to look for advanced python concepts and receive pointers like
- Start building your own projects
- Learn advanced concepts
- Solve Leetcode problems
- Keep experimenting
By this time, either it feels too humongous of a steep climb, or you have concluded programming not something that’s meant for you.
I would have suggested the same 3 months back. Infact I would have even nudged you to attend my Bootcamp. As I was teaching the last batch, something came out. It’s not the technology, programming construct, or what I taught that made the difference. What made the difference was the ability to split the problem into smaller solvable chunks. It is this ability that gave my students to tackle any projects that they wanted to build. You would be using this skill years into the industry as a Software Engineer
As soon as I started to program in chunks, I realized how everything pieced together.
So how to do it? Given a problem, how do you dissect them into smaller solvable chunks? Like how the construction of a building starts with a basement followed by layers of other constructional elements, your program starts with a base structure and layers of logic plugged into it. The skill is not rocket science but comes with a little bit of practice. Your practice can be as simple as solving a single problem in a single Python script.
Let’s start with an example, A calculator program that does the basic mathematical operation. Your first intuition might be to start searching “How would you write a calculator app in Python?” instead, hold your horses. The goal is not to find the answer but to train your brain to solve the problem by yourself.
Now take down a piece of paper or open notepad and answer these questions? It might not come to naturally the first few times and that’s completely fine. But before moving on write down the answers.
- What are the core functionalities of the script?
- What inputs do I need to achieve it?
- How do I get the user input?
- What data do I need to achieve it?
- Do I need to store anything? If so, how? - Files, DB, cloud storage
Here is a tip to ace it, have a conversation like talking to your friend. As the questions that are popping up and answer them. Spend about 10 minutes on it. Set the timer and start
Done? Here is how my answers look like
What are the core functionalities of the script?
- This is easy it’s a calculator with basic functioanlities add, subtract, multiply, divide. That should be good enough for now
What inputs do I need to achieve it?
- Oh I totally forgot about that, I should be able to get the numbers, and what operation they wanna perform
- So that’s two inputs one for number and one for the operation?
- No, we need two numbers + operation, hence 3
- So we are restricting the program to just 2 numbers at any point.
- Yes, lets keep it simple for now
How do I get the user input?
- via command line, I don’t want to build a UI for this. I want to learn more Python not delve into JS right now.
What data do I need to achieve it?
- Just the inputs would suffice, no other data required
Do I need to store anything? If so, how? - Files, DB, cloud storage
- No I am building a volatile calculator without permanent memory.
Now that we have all the answers let put them into a Python program
calculator.py. Let’s write the 4 functionalities we want to support
def add(a, b): pass def sub(a, b): pass def mul(a, b): pass def div(a, b): pass
See, even though it’s a relatively simple program, I laid down the structure and not filled in anything. That’s because it would take the load off when you are solving complex programs. Remember, we are only making the structures right now. Making it functional is the next step. Let’s focus on the inputs and outputs now.
no1 = input("Enter 1st number :: ") no2 = input("Enter 2nd number :: ") operation = int(input("Choose an operation 1. Add \n 2. Sub \n 3. Mul \n 4. Div ")) result = perform_operation(no1, no2, operation) print (result)
This is still an incomplete program. We haven’t defined the
perform_operation function is. All we know is there needs to be a function to perform the same. This is called “Wishful thinking.” Instead of worrying about what the program does, how to get them right, you put pieces of code that you need and bring them to life later
def perform_operation(no1, no2, operation): if operation == 1: return add(no1, no2) if operation == 2: return sub(no1, no2) # finish the rest
We have taken the time to dissect the program into chunks, now go ahead and put them together on your own. Trust me, you have learned enough Python in the past to do this.
Even after doing this exercise, you might still not be comfortable or feel confident that’s why you should do it again and again. Do it enough times, and the next time you see a problem, you will see loops, variables, and functions.
To keep the practice going here are more ideas for you to solve
- Book tracker - An app where you can track all the books you read
- Book Logger - An app where you can take notes for all the books you read
- Web scrapper - Scrape of all the links from a twitter thread.
- Reminder - A program that will remind you about tasks
Practice is the only way to make progress
Need a little more hand holding? Sign up for the mailing list below, I will send you videos of how I crack the problems above step by step.