Learn Python functions, lists, dictionaries and error handling through practical coding examples inspired by Kenyan businesses and student projects.
https://www.instagram.com/reel/DYFMlnHORym/
Learn Python Functions and Data Structures Through Practical Projects
After learning variables, conditions and loops, the next step in Python programming is learning how to organise information and write reusable code.
These skills allow programmers to develop applications that handle multiple products, manage records and solve more complex problems.
At Dazu School of Tech, practical programming exercises can help learners understand how Python concepts apply to real-world situations.
Understanding Python Lists
A list stores multiple items in a single variable.
Imagine a student developing an inventory tracker for a small shop in Thika.
products = [
"Notebook",
"Pen",
"USB Cable",
"Phone Charger"
]
for product in products:
print(product)The program displays each product stored in the list.
Lists can also store numbers for calculations.
daily_sales = [2500, 4200, 1800, 5300]
print("Total sales:", sum(daily_sales))
print("Highest sale:", max(daily_sales))This approach is useful for simple sales reports, task lists and basic data processing.
Using Dictionaries to Store Records
A dictionary stores information as key-value pairs.
For example, a prototype student registration application could store course information like this:
student = {
"name": "Mary Wanjiku",
"course": "Python Programming",
"location": "Nairobi",
"attendance": 90
}
print(student["name"])
print(student["course"])Dictionaries make it easier to organise related information within a program.
A list of dictionaries can represent several students, products or business transactions.
Tuples and Sets
Tuples are useful for grouping values that should not normally be changed after creation.
course_locations = ("Nairobi", "Thika", "Online")Sets store unique values and can help identify duplicates.
registrations = [
"Python",
"Cybersecurity",
"Python",
"Data Science",
"Cybersecurity"
]
unique_courses = set(registrations)
print(unique_courses)Sets are unordered, so the output order may vary.
Writing Reusable Python Functions
Functions help programmers divide a larger problem into smaller tasks.
Imagine a Kenyan business that needs to calculate the total cost of customer orders.
def calculate_order_total(price, quantity):
return price * quantity
print(calculate_order_total(1200, 3))
print(calculate_order_total(750, 4))The same function can calculate totals for different orders without duplicating the calculation.
Functions can also validate input.
def calculate_discount(price, discount_percent):
if price < 0:
raise ValueError("Price cannot be negative")
if not 0 <= discount_percent <= 100:
raise ValueError("Invalid discount percentage")
return price * (1 - discount_percent / 100)
print(calculate_discount(2000, 10))The function calculates the price after a 10% discount on a KSh 2,000 product.
Error Handling in Python
Applications often encounter invalid input, missing files or unexpected data.
try:
price = float(input("Enter product price: "))
if price < 0:
print("Price cannot be negative.")
else:
print("Product price:", price)
except ValueError:
print("Please enter a valid number.")Error handling allows a program to respond more clearly when a user enters invalid information.
Practical Project: A Course Registration Summary
Imagine a student at Dazu School of Tech creating a simple report showing registrations for different training courses.
registrations = [
{"name": "Mary", "course": "Python"},
{"name": "Brian", "course": "Cybersecurity"},
{"name": "Asha", "course": "Python"},
{"name": "Peter", "course": "Data Science"},
{"name": "Grace", "course": "Python"}
]
course_counts = {}
for registration in registrations:
course = registration["course"]
course_counts[course] = course_counts.get(course, 0) + 1
for course, count in course_counts.items():
print(f"{course}: {count} registration(s)")The program counts registrations for each course.
To extend it, add user input, CSV storage, search functionality and a database. This turns a basic exercise into a more advanced software project.
Where Are These Python Skills Used?
Python data structures and functions are useful in:
Retail inventory systems
Student registration applications
Sales and expense reporting
Data science workflows
Cybersecurity log analysis
Web application development
Understanding these fundamentals makes it easier to learn advanced libraries and frameworks.
Learn Practical Python at Dazu School of Tech
A strong Python learning journey involves more than memorising syntax. It requires regular practice, debugging and building applications that solve identifiable problems.
Explore training opportunities at Dazu School of Tech and confirm the current Python curriculum, course fees and learning arrangements.
Build your programming skills one problem at a time.
Frequently Asked Questions
What should I learn after Python basics?
Learn functions, data structures, error handling, file operations, databases and APIs.
Are Python dictionaries useful in real applications?
Yes. Dictionaries are commonly used to represent and process structured information in Python applications.
Can Python help automate a small business?
Yes. Python can automate approved reporting tasks, process files, calculate totals and support business workflows.
What project should I build as a beginner?
Start with a calculator, expense tracker, inventory tool or course registration summary. Improve the project gradually.
Where can I learn Python in Kenya?
Visit Dazu School of Tech to explore available training options.
Continue learning: Explore the next article on Python APIs, databases and automation.
Related articles
programming/ coding FastAPI Python Framework: Learn to Build Modern and High-Performance REST APIs
programming/ coding SQLAlchemy and Django ORM: Learn Python Database Management Without Writing Every SQL Query
programming/ coding Authentication and Authorization in Python: Secure User Access in Backend Applications
programming/ coding JWT and OAuth2 in Python: Learn Modern API Authentication and Token Security
programming/ coding Python API Security: How to Protect Backend Applications from Cyber Threats
programming/ coding Database Relationships in Python: Learn One-to-One, One-to-Many and Many-to-Many Relationships
programming/ coding Python Application Deployment: Learn How to Launch Django and FastAPI Projects Online
programming/ coding Python Programming Course in Kenya: Build Real-World Projects with APIs, Databases and Automation
You might also like
security What is Cybersecurity? A Complete Guide for Beginners
Nov 16, 2026
software development Software Engineering Course in Thika: Build Real Skills, Real Projects, Real Career Opportunities
Nov 13, 2026
beauty el Nails, Acrylic Nails and Nail Art: Which Skills Should You Learn?
Nov 13, 2026
beauty Beauty Skills You Can Learn and Turn Into a Profitable Business in Kenya
Nov 13, 2026
beauty Manicure and Pedicure Course in Kenya: Everything You Need to Know
Nov 13, 2026
beauty : How to Become a Professional Nail Technician in Kenya
Nov 13, 2026