Menu

Algorithms

Inputs, Processes and Outputs

Contents

  1. Planning Inputs, Processes and Outputs
  2. Inputs
  3. Processes
  4. Outputs
  5. Finding Inputs, Processes and Outputs
  6. Prompts and User Input
  7. Inputs, Processes and Outputs in Python

Before you design an algorithm, identify the problem's inputs, processes and outputs. This makes clear what data enters the program, what work is done with it, and what results are produced, so the algorithm you design later has a job for every piece of data.

An example breakdown

A car park ticket machine asks how many hours you want to park for and accepts coins. Breaking the problem down gives you:

PartWhat it covers
Inputsthe number of hours parking is needed, and each coin inserted
Processesadding the coins to find the amount paid, multiplying the hours by the fixed hourly rate to find the cost, comparing the amount paid with the cost, subtracting the cost from the amount paid to find the change
Outputsthe printed ticket showing the hours paid for, the change returned, a message on the display

Why do it before designing

  • Every process needs the data it works on to be available. A fixed hourly rate is known in advance, but the hours and the coins must be supplied before they can be used.
  • Every output has to be produced by something. The machine can only return the correct change because a process has subtracted the cost from the amount paid.
  • You spot gaps early rather than halfway through writing the algorithm, and you avoid asking for data you never use or leaving out a result the program should produce.

Once the three lists are settled, the design is mostly about order: get the inputs, carry out the processes in a sensible sequence, then produce the outputs. The order is forced by the data, because the cost cannot be compared with the amount paid until the coins have been totalled.

An input is data that enters a program or system so that it can be used. Without inputs, a program could only work with values it already holds, so it could never react to a new customer, a new reading or a new choice.

Where inputs come from

  • A user — someone scans a membership card at a till or speaks a command into a microphone.
  • A file — data saved earlier, such as a list of prices or a set of saved settings, is read into the program.
  • A sensor — a device measures something in the real world and passes that measurement in, such as a soil moisture level or a distance.

In all three cases the data comes from outside the program, which is exactly what makes it an input. Data does not have to come from a person: a reading taken by a sensor is just as much an input as a barcode scanned at a till.

Inputs are not the program's own values

Data that the program has already worked out and stored in a variable is not an input, because it came from inside the program. An input is the new data handed in from outside. When a user types a value in reply to input(), that typed value is the input; the variable it is stored in is only a name the program uses afterwards.

Worked example: watering system

A garden watering system needs three pieces of data before it can choose how long to water for.

InputWhere it comes from
The moisture level of the soil, as a percentageA soil moisture sensor
The maximum run time allowed, in minutesA settings file read by the program
The plant type chosen by the gardenerThe user

Each of these comes from outside: the moisture level was measured rather than calculated, the maximum run time was loaded from a file, and the plant type was chosen by a person. Naming the actual data item, such as the soil moisture percentage rather than a vague label, is what makes an input clear.

A process is work that the program does with its data. Inputs arrive and outputs are produced, but in between the data has to be changed, checked or kept track of — that work is the process. Without processes, the data would just sit there.

The kinds of work a process can do

  • Calculations — arithmetic on the data, such as multiplying a price by a quantity or dividing a distance by a time.
  • Comparisons and decisions — testing a value and choosing what happens next, such as checking whether a player's score has beaten the level target and then choosing which screen to show.
  • Counting and totalling — keeping track of how many times something has happened, or adding values together.
  • Storing values — keeping data in a variable while the algorithm runs so that later steps can use it.

One process often does two of these at once. Adding a new value to a running total is a calculation, and the answer has to be stored so the next value can be added to it. The running total grows as the algorithm runs, so it needs a variable to hold it; working it out once and throwing it away would lose everything added before.

Worked example

A Year 10 tutor group runs a bake sale to raise money for an animal shelter, and every cake sells for £2. Each time a cake is sold, £2 is added to a running total — a calculation whose answer has to be stored in a variable. A second variable counts how many cakes have been sold, so its value goes up by one with every sale. After each sale the running total is compared with the group's £120 target, and the decision is whether to put out the “target reached” sign. At any moment, subtracting the running total from £120 shows how much money is still needed — a calculation that uses the stored total and the target.

An output is a result produced by a program or system — anything it sends out so that a person or another device can use it. Every output leaves the program in some form, which is why a program that shows nothing, saves nothing and controls nothing is of little use.

Where outputs can go

An output does not have to be seen. It can be shown on screen, printed on paper, saved to a file, played as sound, or sent as a signal to a device. The choice depends on who or what needs the result: a person reading it, a record kept for later, or a machine that must act.

Type of outputExample
Shown on screenThe final score displayed at the end of a quiz round
PrintedA receipt printed for a repaired bicycle
Saved to a fileA club's attendance list stored so it can be opened again next week
Played as soundA station announcement naming the next platform
Sent as a signalA robot vacuum starting its cleaning cycle at a set time

Signals that control a device

Some outputs carry no words or pictures at all. They are short signals sent to a device, and the device responds by turning itself on or off. This is useful because the program decides when the device should work, while the device supplies the physical effort. For example, a car park barrier stays down until a ticket has been paid; the program then sends a signal that raises the arm. If the signal is never sent, the arm stays where it is.

Outputs are easy to miss

A file written quietly in the background and a signal sent to a device are just as much outputs as a score on screen, even though nobody watches them happen. Judge an output by whether it leaves the program and is used elsewhere, not by whether it appears on a display.

Every problem can be split into three roles: the inputs are the data the program is given or asks for, the processes are the actions it performs on that data, and the outputs are what it must produce.

Imagine a school reading challenge. A program asks for a pupil's name and the number of books they have read. If the number is 10 or more, it shows a Gold award message; otherwise it shows a Keep going message.

InputsProcessesOutputs
the pupil's name
the number of books the pupil has read
compare the number of books with 10
decide which award message to use
the award message (Gold award or Keep going) shown on screen

To find each part, pick out every item of data the program is handed or asks for; those are inputs. Look for the work done on the data — a comparison, a total, a decision — and those are processes. Outputs are the things that must be displayed, printed, saved or used to control a device. Describe each one specifically: a label such as "the count" could mean anything, so write "the number of books read"; "the message" is vague, so name the award message.

If the challenge is changed so results are grouped by tutor group, the extra raw data you need is each pupil's tutor group. A group total is worked out from the book counts, so it is not an additional input. Only new data supplied from outside the program counts.

When a program asks you for data, two separate things happen: the program displays a message, and you type a reply. These two parts have different roles.

The message that asks you to enter data is called a prompt. A prompt is an output, because the program is showing it on screen. It is not the data itself — it is the instruction telling you what to type.

The data you type in response to the prompt is an input, because it enters the program from outside. For example, a bowling alley kiosk might display How many games will you play? — that message is the output. If you type 3, the value 3 is the input.

Prompts in Python

In Python, the input() function displays a prompt and returns a value. The text inside the brackets is shown on screen, so it is an output. The value the function returns is the text you typed, so it is an input. input() always returns text, so int() is used to convert it to a whole number before it is stored.

PartExampleRole
Message shown by the programHow many games will you play?Output
Data typed by the user3Input
# Bowling alley kiosk
games = int(input("How many games will you play? "))
print("Games booked: " + str(games))

Output when the user types 3:

How many games will you play? 3
Games booked: 3

The prompt is the output displayed by input(). The number you type is the input: int() turns the typed text into a whole number, which is stored in games.

Every Python program can be described by how it handles data. A call to input() takes data from the user, so it is an input. A call to print() displays data, so it is an output. The work that changes the input into the output is a process.

Processes include assignment with =, calculations such as adding or multiplying, and if statements that compare values and choose what happens next. Storing a value in a variable is work done by the program, so it is a process too. When an assignment line includes a call to input(), the call is the input and storing the typed value is also a process. The line as a whole is usually classed as an input, because it brings new data into the program.

battery = input("Battery %: ")
battery = int(battery)
after_charge = battery + 20
if after_charge >= 100:
    print("Fully charged")
else:
    print("Not full yet")

Output when the user types 75:

Battery %: 75
Not full yet

Each line in the program has a role. Line 1 gets data from the user. Lines 2 to 4 convert, calculate and decide. The print() lines show a result.

LineRoleReason
1Input (with storage)input() receives the battery percentage typed by the user; = stores it.
2Processint() changes the text to a whole number and = stores it.
3ProcessAdds 20 to the percentage and stores the result.
4 and 6ProcessThe if compares values and chooses a branch; else is part of that decision.
5 and 7Outputprint() displays a message.