大象传媒

Input and output

All programs need data to be added to or removed from code. Data entered into a program, either by the programmer or digitally, are referred to as . These inputs are stored in variables and used to run the program.

In order to keep the user informed about what is happening inside the program, a programmer may choose to include . This is where the data from the program is shown to the user, either on screen or in the form of a physical output such as printouts or signals.

Outputting data and information from a program to a display

A program may need to communicate with a user. This could be to show the outcome of the program, or to request more information to allow the program to run. This is often shown as text on the user鈥檚 screen and is known as output. For example:

OUTPUT 鈥淲elcome to 大象传媒 Bitesize Computer Science鈥

Obtaining user input from a keyboard

A program will require a computer system to perform four main actions in order to communicate with a user:

  1. the user must input into the system
  2. this data must be processed
  3. the outcome is output to the user
  4. the data is stored for later use
Diagram showing the four categories processes fall into, inputs, processes, outputs and storage

Entering data into a program is referred to as data input. Input can come from many automated sources, but the most common is keyboard input from the user. Programs interact with users by requesting input using the keyboard. Most data in a program is stored in a which can be used to hold data inputted by the user. In the example below, the program asks the user to enter their name, which is stored in the variable called 鈥榥ame鈥:

OUTPUT 鈥淧lease enter your name: 鈥
name 鈫 INPUT

Inputted data can be joined with an output to create a single string. This process of joining strings together is called concatenation, for example:

OUTPUT 鈥淧lease enter your name: 鈥
name 鈫 INPUT
OUTPUT 鈥淗ello鈥 + name

In some languages the input and output is combined to form a single statement. For example, in the Python 3 code below, the user is asked for their name and the input is saved in a single statement.

name = input(鈥淧lease enter your name鈥)
print(鈥淗ello鈥, name)