Grade 10
Course ContentProgramming (Python/Java)
Karibu! Welcome to the Exciting World of Programming!
Habari mwanafunzi! Ever used M-Pesa on your phone? Or checked school results on the K.N.E.C portal? Or maybe even booked a ride on Little? All these things are powered by programming! Think of programming as giving a set of instructions to a computer, just like you would give clear directions to a boda boda rider to get you to your destination. Today, we begin our journey to become the ones who write those instructions. We'll start with a friendly and powerful language called Python.
Analogy of the Day: The Boda Boda Rider
Imagine a computer is a very fast, very obedient boda boda rider. But there's a catch: they only understand a special language and need perfectly clear instructions. If you say "Peleka mimi town," they will be confused. Which town? Which route? You must be specific: "Start the engine. Go straight on Waiyaki Way. Turn left at the roundabout. Stop at Kenya National Archives." Programming is learning to give these perfect, step-by-step instructions in a language the computer understands, like Python or Java.
Why Start with Python?
We are starting our journey with Python for a few very good reasons. It's one of the most popular languages in the world for beginners and experts alike!
- Easy to Read: Python code looks a lot like plain English, making it less intimidating and easier to learn.
- Very Powerful: Don't be fooled by its simplicity! Python is used by giants like Google, Safaricom (for data analysis), and Instagram.
- Versatile: You can use it for building websites, analyzing data (like tracking crop yields), creating games, and even in robotics!
Your First Program: "Hello, Kenya!"
In programming tradition, the first thing you learn is how to make the computer say "Hello". Let's give it a Kenyan twist! The main command we will use is print(). This function simply tells the computer to display whatever you put inside the parentheses on the screen.
# This is a comment. The computer ignores it. It's for us humans.
# The code below will print a message to the screen.
print("Hello, Kenya! We are learning to code!")
When you run this code, the computer will display: Hello, Kenya! We are learning to code!. Sawa? You've just written your first program!
Image Suggestion:A vibrant, colourful digital art illustration of a diverse group of young Kenyan students (boys and girls in school uniforms) gathered around a laptop in a modern classroom. The laptop screen is glowing and clearly displays the text "Hello, Kenya!". The students have expressions of excitement and discovery. The background has subtle hints of Kenyan patterns or landscapes.
Variables: The 'Vikapu' of Your Code
Imagine you go to the sokoni (market). You have different baskets, or vikapu, for your shopping: one for nyanya (tomatoes), one for vitunguu (onions), and one for sukuma wiki. In programming, a variable is just like a kikapu. It's a container where you store information and give it a label (a name).
Let's create some variables in Python:
# Storing text (we call this a "string")
student_name = "Juma Omondi"
# Storing a whole number (an "integer")
student_age = 16
# Storing a decimal number (a "float")
school_fees_balance = 5500.50
# Now, let's print them out to see what's in our 'vikapu'
print("Student Name:", student_name)
print("Student Age:", student_age)
print("Fee Balance (Ksh):", school_fees_balance)
Let's Do Some 'Hesabu' (Math) with Python
A computer is basically a super-fast calculator. You can do all sorts of math using simple operators. Let's calculate the area of a small shamba (farm).
The formula for the area of a rectangle is: Area = Length × Width
# Step 1: Create variables for length and width in metres
length_of_shamba = 50
width_of_shamba = 30
# Step 2: Calculate the area and store it in a new variable
area_of_shamba = length_of_shamba * width_of_shamba
# Step 3: Print the result in a clear, readable way
print("The length of the shamba is:", length_of_shamba, "metres")
print("The width of the shamba is:", width_of_shamba, "metres")
print("Therefore, the total area is:", area_of_shamba, "square metres.")
Making Decisions: The If-Else Roadblock
Life is full of decisions. If it's raining, you carry an umbrella. Otherwise, you don't. Computers make decisions using if-else statements. It's like a roadblock or a junction where you check a condition before proceeding.
+-----------------+
| Start |
+-----------------+
|
v
+-----------------+
| Is score >= 40? |-------(No)------>+------------------+
+-----------------+ | print("Fail") |
| +------------------+
(Yes) |
| v
v +------------------+
+------------------+ | Stop |
| print("Pass") | +------------------+
+------------------+
|
v
+------------------+
| Stop |
+------------------+
Let's write a simple program to check if a student's score in a test is a pass mark (let's say 40 and above is a pass).
# Variable to hold the student's exam score
exam_score = 65
# Check the condition
if exam_score >= 40:
print("Congratulations! You have passed the exam.")
else:
print("You did not pass. Please prepare for a re-take.")
Because 65 is greater than or equal to 40, the program will print the "Congratulations" message. Try changing the exam_score to 30 and see what happens!
A Quick Look at Java
While Python is our friendly starting point, in the world of big systems like banking apps (think KCB or Equity Bank apps) and large government systems, a language called Java is very common. Java is more structured and strict. Don't worry about understanding it all now, just notice the difference. Here is "Hello, Kenya!" in Java:
// This is a Java program to print our message
class Main {
public static void main(String[] args) {
System.out.println("Hello, Kenya! This is Java speaking!");
}
}
See? It does the same thing, but needs a bit more setup. The logic is the same, but the syntax (the grammar and rules of the language) is different. Once you master one language, learning another becomes much easier!
Your Challenge!
Now it's your turn to be the programmer! Your mission, should you choose to accept it, is to:
- Create a new Python file.
- Create three variables: one for your name, one for your age, and one for your dream career (e.g., "Software Engineer", "Doctor", "Pilot").
- Use the
print()function to write a sentence that combines all these variables. For example: "My name is Wanjiku, I am 17 years old and I want to be a Robotic Engineer."Good luck, future tech genius! You are officially on your way. Keep practicing and stay curious!
Pro Tip
Take your own short notes while going through the topics.