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 inputData which is inserted into a system for processing and/or storage.. 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 outputData which is sent out of a system.. 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:
- the user must input dataUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions. into the system
- this data must be processed
- the outcome is output to the user
- the data is stored for later use
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 variableA memory location within a computer program where values are stored. 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)