Skip to content
Lesson 6

Input And Output

Every machine that does useful work takes something in, does something with it, and gives something back. Programmers call the first part input and the last part output. The middle part, where the work happens, is the a…

There is more than one way to understand this. If you have only been taught one, you have been taught less than you deserve.

There is more than one way to understand this. If you have only been taught one, you have been taught less than you deserve.

Every machine that does useful work takes something in, does something with it, and gives something back. Programmers call the first part input and the last part output. The middle part, where the work happens, is the algorithm we have already met. Input, process, output. Three words. Almost everything you have ever used, from a calculator to a microwave to your phone, follows this shape. Once you see it, you cannot unsee it.

Start with the radio that your nana keeps on the charpai in the verandah. He turns the knob, the station moves, voices come out of the speaker. The knob is input. The voice is output. Inside the radio, a circuit is the algorithm. It receives a signal from the air, picks the one your nana asked for, and pushes the rest aside. When PTV Home plays a kahaani at four in the afternoon, the input is the same radio waves it has always been, but the output is a story. Same machine, different content, same shape.

A second example, the kanda wali tarazu in your local sabzi mandi. The aalu wala places potatoes on one pan and small iron weights on the other. He moves weights until the two pans hang level. The input is the heap of potatoes. The output is a number, two kilo aur teen pao. The algorithm is the simple physics of balance. Notice that the input is a real, messy thing, dirty potatoes with mitti on them. The output is clean, a number you can write on a parchi. Almost every program in the world does this same trick. It takes the messy world and gives back something countable.

A third example from the classroom. Your maths teacher asks a sawal. Twelve students raise their hand. He picks one, listens to the jawab, says shabaash or thik karo. That whole exchange is input and output. The teacher's question is input to twenty brains. Each brain runs its own algorithm. Twelve brains produce hands raised, eight brains produce silent confusion, one brain produces an answer the teacher hears. Notice the layers. The classroom as a whole has one input and many outputs. Each student has one input and one output. The same shape repeats at different sizes.

Why this matters for programming. When you sit down to write your first program, the first question is not how to write it. The first question is, what does it take in, and what should it give back. A program that adds two numbers takes two numbers in and gives one number back. A program that checks a CNIC number takes thirteen digits in and gives a haan or naheen back. A program that recommends the next chapter for a student takes the student's recent quiz scores in and gives a chapter title back. If you cannot describe the input and the output in one short Urdu or English sentence, you are not yet ready to code. Sit with the problem until you can.

One last thought before the next lesson. The most useful programs in Pakistan in the next ten years will be the ones that take inputs other people ignore and turn them into outputs other people need. A photo of a kiryana shop ka khata ka panna, in, a typed list of items and prices, out. Twelve voice notes from a parent in Saraiki, in, one written summary the school can read in Urdu, out. The shape, input, process, output, is fixed. The choice of what to feed in and what to ask for back is where the real work, and the real opportunity, lives.

Estimated time: 12 min