Grade 7
Course ContentProgramming logic (Visual/Block)
Habari Mwanafunzi! Jenga na Fikiri: Safari Yako ya Kwanza ya Coding!
Umewahi kumpa mtu maelekezo ya jinsi ya kutengeneza kikombe cha chai moto? Au kumwelekeza dereva wa matatu njia ya mkato kule mtaani? Kama umewahi, basi hongera, tayari unaelewa msingi wa kwanza wa coding! Ku-code ni kama kumpa kompyuta maelekezo waziwazi, hatua kwa hatua. Tofauti ni kwamba, kompyuta haielewi "hapo mbele kidogo", inahitaji maelekezo kamili!
Leo, tutaanza safari yetu kwa njia rahisi na ya kufurahisha zaidi: Visual/Block Programming. Fikiria ni kama unajenga na LEGOs; badala ya matofali, unatumia "blocks" za maelekezo ili kuunda kitu cha kushangaza kwenye kompyuta!
Fikiria Hivi: Unataka kujenga gari la LEGO. Unachukua gurudumu, unaliunganisha na mwili, unaweka kiti, na kisha unaweka usukani. Kila kipande kina kazi yake, na unaviunganisha kwa mpangilio sahihi. Ndivyo ilivyo na block programming!
Mantiki ya Uprogramu (Programming Logic) ni Nini?
Kabla hatujaanza kuburuta na kuangusha blocks, hebu tuzungumzie "ubongo" wa coding: Logic. Hii ni seti ya sheria na mpangilio unaotumia kutatua tatizo. Ni kama mapishi ya chapati. Hauwezi kuanza kukaanga kabla ya kukanda unga! Mpangilio ni muhimu sana.
Kuna dhana tatu kuu za msingi unazopaswa kujua:
- Sequence (Mfuatano): Hii inamaanisha kufanya mambo kwa mpangilio sahihi, hatua moja baada ya nyingine.
- Conditions (Masharti): Hii ni kufanya maamuzi. "KAMA mvua inanyesha, BASI beba mwavuli."
- Loops (Marudio): Hii ni kurudia kitendo fulani mara nyingi ili kuokoa muda. "RUDIA kukata sukuma wiki MPAKA zote ziishe."
Image Suggestion:
A colorful, vibrant digital illustration of a Kenyan student's desk. On the desk is a cookbook open to a recipe for "Chapati," a plate of chapati, and a laptop showing a simple Scratch-like interface with blocks labeled 'Kanda Unga' (Knead Dough), 'Sukuma' (Roll), and 'Pika' (Cook) arranged in a sequence. The style should be cheerful and educational.
Tuanze Kazi: Programu Yetu ya Kwanza!
Hebu tumtumie mhusika wetu, anayeitwa Simba, kumfanya atembee na kusema "Jambo!". Tutatumia blocks zetu za kufikirika.
Hatua ya 1: Sequence (Mfuatano)
Mpangilio wetu wa kwanza ni rahisi. Simba lazima atembee kwanza, kisha aseme "Jambo!".
[ WHEN GREEN FLAG CLICKED ] <-- Hapa ndio tunaanza
|
+--> [ MOVE 50 STEPS ]
|
+--> [ SAY "Jambo!" ]
Hapa, kompyuta itafuata maelekezo kutoka juu kwenda chini, bila kuruka hatua yoyote.
Hatua ya 2: Loops (Marudio) kwa Ufanisi
Vipi kama tunataka Simba atembee umbali mrefu? Tunaweza kurudia block ya 'MOVE' mara nyingi, lakini hiyo ni kazi ngumu! Badala yake, tutatumia Loop.
[ WHEN GREEN FLAG CLICKED ]
|
+--> [ REPEAT 4 TIMES ]
|
+--> [ MOVE 25 STEPS ] <-- Hii itarudiwa mara 4
|
+--> [ SAY "Nimefika!" ]
Hapa, Simba atasonga mbele hatua 25, mara nne mfululizo (jumla ya hatua 100), kisha atasema "Nimefika!". Ni njia ya haraka na nadhifu zaidi!
Hatua ya 3: Conditions (Masharti) kwa Akili
Hebu tuifanye programu yetu iwe na akili kidogo. Tunataka Simba ageuke anapofika ukingoni mwa skrini.
Kwa hili, tunatumia block ya IF...THEN... (KAMA...BASI...). Hii ni kama njia panda barabarani.
Is Simba touching the edge?
/ \
/ \
YES NO
| |
| |
[ Turn Around ] [ Keep Walking ]
Katika blocks, itaonekana hivi:
[ FOREVER ] <-- Loop inayorudia milele
|
+--> [ MOVE 10 STEPS ]
|
+--> [ IF touching edge? THEN ]
|
+--> [ TURN 180 DEGREES ]
Sasa, Simba atatembea bila kikomo, na kila anapogusa ukingo, atageuka na kuelekea upande mwingine. Amekuwa na akili!
Mfano Halisi wa Kenya: Mantiki ya Wakala wa M-Pesa
Hebu fikiria jinsi wakala wa M-Pesa anavyofanya kazi. Anafuata mantiki maalum kila anapohudumia mteja anayetaka kutoa pesa.
Mteja anafika na anasema, "Nataka kutoa shilingi 2,000."
mantiki ya Wakala inaanza:
1. ULIZA: "Nipe namba yako ya simu na kitambulisho tafadhali." (Input)
2. ANGALIA (CONDITION): KAMA jina kwenye kitambulisho linalingana na jina la M-Pesa, BASI endelea. LA SIVYO, sitisha na umwambie mteja kuna tatizo.
3. ANGALIA (CONDITION): KAMA mteja ana salio la kutosha (zaidi ya 2,000), BASI idhinisha utoaji. LA SIVYO, mwambie mteja "Huna salio la kutosha."
4. TENDO (SEQUENCE): Mpe mteja shilingi 2,000 taslimu.
5. TENDO (SEQUENCE): Subiri ujumbe wa uthibitisho.
6. RUDIA (LOOP): Mhudumie mteja anayefuata kwenye foleni.
Tupige Hesabu na Blocks!
Kompyuta ni hodari sana kwenye hisabati. Hebu tuone jinsi ya kuhesabu gharama ya kununua maandazi matatu, ambapo andazi moja ni shilingi 20.
// Hatua 1: Tunatengeneza "variables" (visanduku) za kuhifadhi namba
[ SET bei_ya_andazi TO 20 ]
[ SET idadi_ya_maandazi TO 3 ]
// Hatua 2: Tunafanya hesabu
[ SET gharama_jumla TO (bei_ya_andazi * idadi_ya_maandazi) ]
// Hatua 3: Tunaonyesha jibu
[ SAY "Jumla ni Shilingi: " + gharama_jumla ]
Kompyuta itafuata hatua hizi na kuonyesha jibu: "Jumla ni Shilingi: 60". Rahisi, sivyo?
Hitimisho: Wewe Sasa ni Mtatuzi wa Matatizo!
Leo tumejifunza misingi mitatu muhimu ya coding: Sequence (Mfuatano), Conditions (Masharti), na Loops (Marudio). Hizi ndizo "LEGO blocks" unazotumia kujenga karibu programu yoyote unayoweza kufikiria.
Kumbuka, coding siyo tu kuandika maelekezo; ni kuhusu kufikiria kimantiki na kuvunja matatizo makubwa kuwa hatua ndogo, zinazoweza kudhibitiwa. Umepiga hatua kubwa leo!
Kazi nzuri! Sasa nenda kwenye jukwaa kama Scratch na ujaribu kutengeneza kitu! Labda mhusika akiruka juu ya jengo la KICC au bendera ya Kenya ikipepea. Uwezo ni wako!
Habari Future Tech Whiz! Let's Talk Logic!
Imagine you're trying to explain to your friend how to get from the Nairobi National Archives to the KICC. You can't just say "Go there!" You have to give them clear, step-by-step instructions: "First, walk straight down Moi Avenue. Then, at the roundabout, turn right onto City Hall Way. Walk past the Parliament buildings, and you will see the KICC on your left."
Congratulations! You just used programming logic. It's the art of creating a clear, ordered set of instructions to achieve a goal. Today, we're going to explore this amazing skill using a fun and easy method: Visual, or Block-based, programming!
What is Programming Logic Anyway?
Think of it as the recipe before you start cooking. Before you make a delicious pot of ugali, you need a plan in your head:
- Boil the water.
- Pour in the maize flour slowly.
- Stir continuously until it's firm.
- Let it cook for a few minutes.
- Serve with your favourite sukuma wiki!
If you mix up these steps, you'll end up with a mess! Programming logic is the same—it's the smart thinking and planning that tells the computer what to do, in what order, and when.
With Visual/Block Programming (like on platforms such as Scratch), we don't write complicated text. Instead, we connect colourful blocks together, just like building with LEGOs. This lets us focus purely on the logic, the "recipe," without worrying about spelling or complicated symbols. It's the perfect way to start your coding journey!
Image Suggestion: A vibrant, colourful digital illustration of a group of diverse Kenyan students (in school uniform) gathered around a laptop. On the screen, they are dragging and dropping colourful code blocks (like those from Scratch). The atmosphere is full of excitement and discovery. One student is pointing at the screen with a 'eureka!' expression.
The Core Building Blocks of Logic
Every program, from a simple game to an app like M-Pesa, is built using a few key logical ideas. Let's break them down!
1. Sequence: The Straight Path
A sequence is a series of instructions that the computer follows one after the other, in a specific order. Just like the steps to top up airtime on your phone—each step must follow the previous one.
ASCII Art: A Simple Sequence
[ Start Program ]
|
V
[ Move 10 steps forward ]
|
V
[ Say "Habari Dunia!" for 2 secs ]
|
V
[ Play a drum sound ]
|
V
[ End Program ]
2. Events: The Starting Gun!
An event is a trigger that starts a sequence of actions. It's the "When..." part of a command. Think about school: When the bell rings at 10:30 AM, you know it's time for break time. The bell is the event!
ASCII Art: An Event Block
[ When Green Flag is Clicked -> ]---->[ Start the sequence ]
In block programming, common events are "When the green flag is clicked," "When a key is pressed," or "When a character is clicked."
3. Loops (Repetition): "Rinse and Repeat"
Why write the same instruction 10 times? A loop lets you repeat an action or a set of actions over and over. Imagine a farmer weeding a shamba. They perform the same action—bend, pull weed, move—for every plant in the row. That's a loop!
ASCII Art: A Loop Block
[ Repeat 4 times ]------------------.
| |
| [ Move 50 steps forward ] |
| |
| [ Turn right 90 degrees ] |
| |
'-----------------------------------'
(This simple loop would make a character walk in a perfect square!)
4. Conditionals (Selection): The "What If?" Game
Life is full of choices, and so is programming! Conditionals allow your program to make decisions. They use "If... Then... Else..." logic. If it is raining, then you will carry an umbrella, else you will wear sunglasses.
Real-World Scenario: A matatu driver is approaching a junction. IF the traffic light is green, THEN they will proceed. ELSE IF the light is yellow, THEN they will slow down. ELSE (if the light is red), they will stop. That's conditional logic in action on our very own Kenyan roads!
ASCII Art: A Conditional Flowchart
[ Is it raining? ]
/ \
/ \
(Yes) (No)
/ \
/ \
V V
[ Carry an umbrella ] [ Wear sunglasses ]
5. Variables: The Magic Storage Boxes
A variable is like a labelled box or a kibubu (piggy bank) where you can store information that might change. You could have a variable called `score` in a game. Every time you score a point, the number inside the `score` box increases.
Let's use a variable to calculate the total cost of items at a local duka.
Step 1: Create variables (our boxes)
- Box labeled 'price_of_soda' = 60 KSh
- Box labeled 'price_of_bread' = 70 KSh
- Box labeled 'total_cost' = 0
Step 2: Perform the calculation
'total_cost' = 'price_of_soda' + 'price_of_bread'
Step 3: Check the value in the 'total_cost' box
'total_cost' is now 130 KSh
Let's Put It All Together: An M-Pesa Scenario
Let's think logically about buying something with M-Pesa. Here's how a program might "think" using all our concepts:
EVENT: When you press "OK" on the M-Pesa confirmation screen.
SEQUENCE:
- VARIABLE: Get your current `account_balance`.
- VARIABLE: Get the `cost_of_item`.
- CONDITIONAL: IF `account_balance` is greater than or equal to `cost_of_item`...
- THEN...
- Subtract `cost_of_item` from `account_balance`.
- Send a confirmation SMS.
- ELSE...
- Send an "Insufficient funds" error message.
See? All those fancy apps are just built from these simple, logical blocks.
Image Suggestion: A split-screen image. On the left, a simplified flowchart diagram showing the "IF balance > cost" logic with icons (a money bag, a shopping cart, a green checkmark, a red cross). On the right, a close-up of a smartphone screen in Kenya displaying an M-Pesa confirmation message.
Your Turn, Future Programmer!
You have just learned the fundamental "thinking" that powers all technology around you. This logic is the same whether you're building a simple animation or the next big tech solution for Kenya!
The best way to get better is to practice. I encourage you to explore free platforms like Scratch from MIT or Blockly from Google. Start by making a character move, then make it draw a shape using a loop, and then make it react to your clicks using conditionals. You are not just playing; you are training your brain to think like a creator, an innovator, and a programmer.
You've got this! Keep thinking, keep building, and keep being curious.
Habari Mwanafunzi! Let's Build with Digital Blocks!
Welcome to the exciting world of programming logic! Now, I know the word "programming" can sound a bit intimidating, like something for geniuses in a dark room. But let me tell you a secret: if you can give someone directions from the Nairobi CBD to Uhuru Park, or if you can follow a recipe to cook the perfect ugali, you already understand programming logic! It's all about giving clear, step-by-step instructions. Today, we'll learn how to give these instructions to a computer using fun, colourful digital blocks instead of complicated text.
Image Suggestion: A vibrant and colourful digital illustration of diverse Kenyan students (boys and girls) gathered around a large computer screen. The screen shows a Scratch-like interface with bright, interlocking blocks of code. They are pointing, smiling, and collaborating, with a background hinting at a modern Kenyan classroom or tech hub.
What is Programming Logic, Anyway?
Think of it as the recipe for a computer program. Before you cook, you need a plan: first, you gather ingredients, then you mix them, then you cook them for a specific time. You can't fry the onions *after* you've already served the food, right? The order and the rules matter! Programming logic is simply that: defining the correct order of steps and the rules for the computer to follow to achieve a goal.
Real-World Scenario: The Ugali RecipeMaking ugali is a perfect example of a sequence in programming.
- START
- Boil water in a sufuria.
- Pour in maize flour.
- Stir continuously until it's a firm dough.
- Let it cook for a few minutes.
- Serve.
- END
If you mix up these steps, you'll end up with a mess, not ugali! A computer is the same; it needs the exact steps in the correct order.
The Core Building Blocks of Visual Programming
In visual or block programming (like on platforms such as Scratch or Blockly), we don't type words. We connect blocks that represent commands. Let's look at the most important ones.
1. Sequence (The Order of Things)
This is the most basic concept. It's just a set of instructions that the computer will follow one after the other, from top to bottom. Just like our ugali recipe!
[ Start Program ]
|
V
[ Move 10 steps ]
|
V
[ Say "Jambo!" for 2 secs ]
|
V
[ Play a drum sound ]
|
V
[ End Program ]
2. Loops (Doing it Again and Again)
Imagine you have to tell a character to jump 5 times. You could use 5 "jump" blocks. But what if you wanted it to jump 100 times? That would be tiring! A loop lets you repeat an action a specific number of times, or even forever.
Kenyan Example: A Kiondo WeaverA person weaving a kiondo bag performs the same action over and over: 'over, under, pull tight'. Instead of writing this instruction a thousand times, you would just say: REPEAT 'over, under, pull tight' UNTIL the bag is finished. That is a loop!
ASCII Art of a Loop Block:
+-------------------------+
| REPEAT 4 TIMES |
| +---------------------+ |
| | Move 50 steps | |
| +---------------------+ |
| +---------------------+ |
| | Turn right 90 deg | |
| +---------------------+ |
+-------------------------+
(Can you guess what shape this loop will draw? That's right, a square!)
3. Conditionals (Making Decisions - The "IF" Game)
Life is full of decisions. IF it's raining, THEN you carry an umbrella, ELSE you wear sunglasses. Computers need to make decisions too! We use If-Then-Else blocks for this. The computer checks if a certain condition is true, and then acts based on the answer.
ASCII Flowchart for a Conditional:
+-----------------+
| Is it raining? | --(YES)--> [ Take an umbrella ]
+-----------------+
|
(NO)
|
V
[ Wear sunglasses ]
Kenyan Example: M-Pesa BalanceImagine you want to send Ksh 500 to a friend.
IF your M-Pesa balance is greater than 500, THEN the transaction is successful. ELSE, you get a message saying "You have insufficient funds."
4. Variables (Boxes for Storing Information)
A variable is like a labelled box where you can store something that might change. For example, you can have a box called `score` in a game. Every time you answer a question correctly, you add points to the box.
Let's calculate the new M-Pesa balance after buying airtime worth Ksh 100. We'll use a variable called `balance`.
Step 1: Create a variable to hold the starting balance.
SET [balance] TO 1500
Step 2: Perform the calculation (the transaction cost).
SET [balance] TO ( [balance] - 100 )
Step 3: The result.
The value inside the `balance` variable is now 1400.
Image Suggestion: A clean, infographic-style image. It should have four quadrants, each dedicated to a core concept: Sequence (showing blocks stacked vertically), Loop (showing a 'repeat' block wrapping other blocks), Conditional (showing an 'if/else' block with two paths), and Variable (showing a block labelled 'score' with a number '0' inside it).
Let's Bring it All Together: A Simple Animation!
Imagine we want to create a simple animation of a safari jeep moving across the screen. When it reaches the end, it says "We've arrived at the Mara!" and stops.
Here's how we would think about it using our blocks:
- We need it to start when we click the green flag (an Event).
- We need it to move continuously (a Loop).
- We need it to check IF it has reached the edge (a Conditional).
- Once it reaches the edge, it should stop everything.
[ WHEN Green Flag CLICKED ]
|
V
+------------------------------------+
| REPEAT FOREVER |
| |
| +----------------------------+ |
| | Move 5 steps | |
| +----------------------------+ |
| |
| +----------------------------+ |
| | IF (touching edge of screen?) | |
| | +--------------------------+ |
| | | THEN Say "Tuko Sawa!" | |
| | | Stop all scripts | |
| | +--------------------------+ |
| +----------------------------+ |
| |
+------------------------------------+
See? By combining these simple blocks, you've created the logic for a complete little program. You are a programmer!
From Blocks to Big Things
Every complex app, website, and game you use—from M-Pesa to your favourite video game—is built on these same fundamental principles: sequences, loops, conditionals, and variables. Block programming is like learning to ride a bicycle with training wheels. It helps you master the balance and steering (the logic) without worrying about falling (syntax errors). Once you are comfortable with the logic, transitioning to text-based languages like Python or JavaScript becomes much, much easier.
Kazi ya Ziada (Your Challenge!)
Now it's your turn to be the creator! Your challenge is to think logically.
- Go to a free website like Scratch (scratch.mit.edu).
- Try to create a program where a character asks for your name and then says, "Jambo, [Your Name]!". (Hint: You will need a 'ask and wait' block and a variable to store the answer!).
- Challenge yourself further: Can you make the character dance if the name given is "Simba"? (Hint: You will need an If/Then block!).
Remember, the goal is not to be perfect, but to try, experiment, and see how powerful these simple blocks can be. You are learning the language of the future. Kila la kheri!
Pro Tip
Take your own short notes while going through the topics.