๐ฃ๐๐๐ต๐ผ๐ป ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด: ๐๐ฟ๐ผ๐บ ๐ช๐ผ๐ฟ๐ธ๐ถ๐ป๐ด ๐๐ผ๐ฑ๐ฒ ๐๐ผ ๐ฆ๐บ๐ฎ๐ฟ๐๐ฒ๐ฟ ๐๐ผ๐ด๐ถ๐ฐ
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.