𝗣𝘆𝘁𝗵𝗼𝗻 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴: 𝗙𝗿𝗼𝗺 𝗪𝗼𝗿𝗸𝗶𝗻𝗴 𝗖𝗼𝗱𝗲 𝘁𝗼 𝗦𝗺𝗮𝗿𝘁𝗲𝗿 𝗟𝗼𝗴𝗶𝗰
I solved two classic programming problems in Python.
I did not start with code. I used this process:
- Understand the problem.
- Think about the logic.
- Sketch a flowchart.
- Write the code.
Problem 1: Sum of first N numbers. I tried three ways:
- A while loop. It worked.
- A for loop. It was cleaner.
- A math formula. It was fastest.
The formula removes the loop. It runs in constant time.
Problem 2: Sum of prime numbers. My first version checked every number. I wasted time on even numbers. I improved it by:
- Skipping all even numbers.
- Skipping even divisors.
This made the code faster.
The biggest lesson was not about Python syntax. It was about how programmers think.
My growth looked like this:
- Working code.
- Cleaner code.
- Faster code.
- Smarter logic.
Do not worry about perfect code at first. Make it work. Make it better.