1.2 Inputs, outputs and eventsWhat goes in, what comes out, and what sets it off

Program input is data sent to a computer for processing by a program. Input comes in four forms: tactile (a tap, a click, a button press), audio (speech into a microphone), visual (a camera image, a scanned code), and text (typed words or numbers). Input can come from a user or from another program, like a weather service sending today's forecast to your phone, or a file the program reads.
Program output is any data sent from a program to a device: text or images on a screen, sound from a speaker, a vibration, a message sent to another program. Output is usually based on the program's input, or on its prior state, meaning values it already had stored. A step counter shows a number based on what its sensor reported (input) and how many steps it had counted so far today (prior state).
?Wait, what does INPUT() do on the exam?
Events and event-driven programs
Many inputs arrive as events. An event is associated with an action and supplies input data to a program. Events are generated when a key is pressed, a mouse is clicked, a program starts, a timer runs out, or any other defined action happens that affects the flow of execution.
That leads to a big idea about how programs run. Some programs run sequentially: statement 1, then statement 2, then 3, top to bottom, like the tip splitter. In event-driven programming, statements run when they are triggered by an event, not just in the order they were written. A game's jump code sits there doing nothing until the space bar is pressed. The "Send" code in a chat app waits for the tap. Most apps you use are event-driven.
| Event | Kind of input | Code that runs |
|---|---|---|
| Tap the Add button | Tactile | Save the new task to the list |
| Say "next song" | Audio | Skip to the next track |
| Camera sees a QR code | Visual | Open the linked menu |
| Type a city and press Enter | Text | Look up its weather |
| App is opened | A defined action | Load the saved settings |
Sequential flow
- Statements run in order, top to bottom
- The program decides when each line runs
- Example: a script that computes a grade and displays it
Event-driven
- Code runs when an event triggers it
- The user (or a sensor, or a timer) decides when
- Example: a music app that waits for you to tap Play
?Wait, what's "prior state"?
I thought about it. Show me
- Inputs: the user's spoken word (audio). Also any taps to start or skip (tactile).
Why?
Inputs are data sent into the program for processing. - Outputs: the picture (visual), the spoken word "perro" (audio), the buzz (tactile), the new score and the spelling on screen (visual or text).
Why?
Outputs are data the program sends to a device: screen, speaker, vibration motor. - Event: the microphone finishing a recording, or a tap, triggers the code that checks the answer.
Why?
An event is an action that supplies input and triggers code. - Notice the score: its output depends on the input (right or wrong) and on prior state (the score before).
Answer: Inputs: spoken word (audio), taps (tactile). Outputs: picture (visual), spoken word (audio), buzz (tactile), score and spelling (visual text). Event: the recording finishing, or a tap, triggers the checking code.
Stuck? Get a hint
- Ask for each item: is it going into the program, or coming out of it?
- Sounds can be both: the app plays one (output) and hears one (input).
- An event is the action that makes code run.
- AA program that computes the average of 100 numbers and then displays it
- BA drawing app that draws a dot wherever the user clicks
- CA program that displays the numbers 1 to 10 in order
- DA calculator that always multiplies the same two numbers when it starts
Show the answer
B. Each click is an event, and the dot-drawing code runs only when a click triggers it. The other three run straight through in a fixed order, which is sequential flow.
- Aa tactile input
- Ba tactile output
- Can audio input
- Dan event that the user generates
Show the answer
B. The vibration is data the program sends to a device, the vibration motor, so it is an output, and you feel it, so it is tactile. The trap is "tactile input": a tap on the watch would be a tactile input.
- Input: data sent to a program. Tactile, audio, visual or text, from a user or another program.
- Output: data sent from a program to a device. Usually based on input or prior state.
- An event is an action (click, key press, program start, timer) that supplies input and triggers code.
- Event-driven programs run code when events trigger it, not only in order from top to bottom.