What is input and output in programming
In the last lesson we put values into boxes. But how do we see those values, and how do we give the program new ones? Let's look at the two directions in which a program and we talk to each other.
A conversation goes two ways
Just as people talk with each other, we talk with programs.
The computer shows us something, and we give the computer something.
These two directions are how every program communicates.
Two directions between the computer and us.
What the computer shows is called output, and what we give it is called input.
With just these two, you can have any conversation you like with a program.
Output puts a value on the screen
First, output: showing a value the program holds on the screen.
Remember the boxes (variables) from the last lesson.
Say "show the value in the greeting box," and that value appears on the screen.
Press the button below and the greeting appears.
Output a variable's value to the screen.
Thanks to output, we can see the values inside the computer.
Calculation results or stored information: if it isn't output, we have no way of knowing.
Input takes a value and puts it in a box
The other direction is input.
When we type letters or numbers, that value is stored in a variable, as in "take the name as input and put it in the name box."
Input always ends with something going into a box.
Type a name in the field below and press the input button, and it goes into the box.
The value you type goes into a variable.
Thanks to input, the program listens to us.
The same code behaves differently depending on the value you give it.
Type a name, for example, and it greets you by that name.
Take turns and it's a conversation
Alternate output and input, and a real conversation begins.
The computer asks (output), we answer (input), and the computer replies (output).
This back-and-forth is the basic skeleton of every app we use.
Ask (output) · answer (input) · reply (output).
Chat apps, games, search boxes: they're all really this.
Complicated things are simply stacked on top of a repeating loop of output and input, asking and answering.
A program that takes input and says hello
Now let's combine the two into a small program.
It takes a name and an age as input and uses them to build a greeting that it shows on the screen (output).
Enter the values and press run, and the result is built from what you typed.
Input → processing → output.
Take in a value through input, make something with it, and show it through output.
This flow is the basis of a program.
In the next lesson, we'll look at whether these values are numbers or text: their types.