When I started learning Python, I was mostly telling it what to print.
Then I discovered if statements and loops.
And suddenly, Python could make decisions, repeat tasks, and even help me analyse data. ๐
That was when things started getting interesting.
๐ง Teaching Python to Make Decisions
I learned that comparison operators allow Python to ask questions:
score = 75
print(score >= 50) # True
print(score < 50) # False
Then came if, elif, and else:
score = int(input("Enter your score: "))
if score >= 80:
print("Grade A")
elif score >= 70:
print("Grade B")
elif score >= 60:
print("Grade C")
elif score >= 50:
print("Grade D")
else:
print("Grade F")
Basically, I was teaching Python:
โIf this happens, do this. Otherwise, try something else.โ
๐ Decisions Inside Decisions
I also learned about nested if statements.
For example, checking a login:
username = input("Username: ")
if username == "admin":
password = input("Password: ")
if password == "Kenya2025":
print("Welcome Admin")
else:
print("Wrong Password")
else:
print("User not found")
One decision leads to another decision.
Suddenly, my code was starting to look like a little flowchart.
๐ Then I Discovered Loops
If statements help Python decide.
Loops help Python repeat.
Instead of writing:
print("Good Morning Alice")
print("Good Morning Brian")
print("Good Morning Jane")
I can simply write:
names = ["Alice", "Brian", "Jane"]
for name in names:
print(f"Good Morning, {name}")
One instruction. Multiple results.
That felt like unlocking a new level. ๐ฎ
๐ฐ My Accounting Brain Got Excited
One of my favourite exercises was adding M-Pesa transactions:
transactions = [1500, 3000, 800, 12000, 450, 2700]
total = 0
for amount in transactions:
total += amount
print(f"Final total: Ksh {total}")
Now Python can go through each transaction and calculate the total for me.
This is where I started seeing the connection between Python, finance and data analytics.
๐ฏ And Then I Built a Savings Calculator
I used a while loop to calculate how long it would take to reach a savings goal:
saving_goal = int(input("Savings goal: "))
monthly_savings = int(input("Monthly savings: "))
total = 0
months = 0
while total < saving_goal:
total += monthly_savings
months += 1
print(f"It took {months} months to reach Ksh {total}")
For a goal of Ksh 50,000 and monthly savings of Ksh 8,000, Python tells me it takes 7 months, reaching Ksh 56,000.
And honestly, watching a few lines of code solve a real-world problem is becoming addictive. ๐
๐ What I'm Learning
My Python journey is slowly changing from:
โWhat does this code mean?โ
to:
โWhat problem can I solve with this?โ
So far, I've learned:
if โ make decisions
for โ repeat through items
while โ keep going until a condition changes
and / or โ combine conditions
break โ stop a loop
accumulators โ keep running totals
I'm still very much a beginner, but I'm starting to understand something important:
Programming isn't just about writing code. It's about learning how to break a real-world problem into instructions a computer can understand.
And I'm enjoying the process, one bug at a time. ๐๐ป
Top comments (0)