Source: https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-2-1-input-and-output

[Revision notes](https://senecalearning.com/en-gb/revision-notes.md) › [GCSE](https://senecalearning.com/en-gb/revision-notes/gcse.md) › [Coding](https://senecalearning.com/en-gb/revision-notes/gcse/coding.md) › [National Curriculum](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum.md) › Input & Output

# Input & Output

Coding: Introduction to Python v3, topic 1.2.1

## Input

There must be some mechanism for the user to input data to the computer.

### What data can I input?

![What data can I input?](https://image-v2.cdn.app.senecalearning.com/2018-08/896bfbb3-c1ee-4792-89b4-6bedd4f46136/metadata-data-.jpg)

- Data can be input from any device connected to the computer.
- The keyboard is the most common data input device for command line programs.
- We will only look at keyboard input in this course.

### The input function

![The input function](https://image-v2.cdn.app.senecalearning.com/2018-05/5a9662ab-b70b-4e5b-911b-d70513b89d02/shutterstock_747571558.jpg)

- Python has a built in function (command) which allows us to take keyboard input.
- We can use the code: input(“Prompt”) to take the input.
- We can write any text for the “Prompt”, which will be displayed to the user before they type their response.
- A prompt is a message that is displayed to the user before they type their response.

### Data type of input

![Data type of input](https://image-v2.cdn.app.senecalearning.com/2018-08/6678c24d-96b2-4f4b-8c75-3883dade05bf/corrupted-data-.jpg)

- When data is entered from the keyboard, it is automatically a ‘string’.
- A string is a sequence of character inputs from the keyboard, for example ‘Hello’.

## Output

Output is necessary so that we can see the results of programs.

### Why do we need outputs?

![Why do we need outputs?](https://image-v2.cdn.app.senecalearning.com/2018-09/2d01dd30-e1e4-455b-b291-78ae3261cb96/tv-child-watch-boy-.jpg)

- Outputs are important so that we can communicate the result of a program to the user.
- Outputs are usually delivered as text onto the screen.

### The print function

![The print function](https://image-v2.cdn.app.senecalearning.com/2018-08/2cab83d7-a047-4490-bdf0-ce2e662f6d26/printing-press-print-.jpg)

- The output function in Python is called ‘print’.
- The output function ‘prints’ data onto the screen.
 - E.g. print(“Hello, world!”) would output the text “Hello, World!”.

### What data can be outputted?

![What data can be outputted?](https://image-v2.cdn.app.senecalearning.com/2018-07/1067548c-e876-492c-a3c9-a8b266f0b1e6/Manipulation-Puppet-Strings-.jpg)

- Output data must be a string before we can print it.
- If we want to combine non-string data with text, we must first cast it to a string.
 - Otherwise, print() can display non-string data directly.

## Test yourself on Input & Output

- What is the most common input device for command line programs?
- What data type is keyboard input?
- Data can only be input from a keyboard. True or false?
- How are outputs usually delivered in a command line program?
- Why are output statements used?

[Practise this topic for free](https://app.senecalearning.com/classroom/course/72d0364c-db0a-4630-8e0a-61f48cae0252/section/88b6911b-5c00-4ba9-92dc-78ff692ce926/session)

- Previous topic: [1.1.1 Python](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-1-1-python.md)
- Next topic: [1.3.1 Data Types](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-3-1-data-types.md)

## Coding: Introduction to Python v3 contents

### 1 Introduction to Python
- 1.1 Python
  - [1.1.1 Python](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-1-1-python.md)
- 1.2 Input & Output
  - [1.2.1 Input & Output](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-2-1-input-and-output.md)
- 1.3 Data Types
  - [1.3.1 Data Types](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-3-1-data-types.md)
- 1.4 Variables & Constants
  - [1.4.1 Variables & Constants](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-4-1-variables-and-constants.md)
- 1.5 Operators
  - [1.5.1 Arithmetic & Relational Operators](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-1-arithmetic-and-relational-operators.md)
  - [1.5.2 Boolean & Assignment Operators 2](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-2-boolean-and-assignment-operators-2.md)
- 1.6 Program Flow
  - [1.6.1 Selection](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-1-selection.md)
  - [1.6.2 Iteration](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-2-iteration.md)

### 2 Data Structures
- 2.1 Lists & Strings
  - [2.1.1 Lists](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-1-lists.md)
  - [2.1.2 Strings](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-2-strings.md)
- 2.2 File Handling
  - [2.2.1 File Handling](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-2-1-file-handling.md)

### 3 Modularity
- 3.1 Subroutines
  - [3.1.1 Subroutines](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-1-1-subroutines.md)
- 3.2 Data Flow
  - [3.2.1 Data Flow](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-2-1-data-flow.md)

### 4 Good Practice
- 4.1 Naming & Whitespace
  - [4.1.1 Identifiers](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-1-identifiers.md)
  - [4.1.2 Whitespace](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-2-whitespace.md)
- 4.2 Comments
  - [4.2.1 Comments](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-2-1-comments.md)
- 4.3 Exceptions
  - [4.3.1 Exceptions](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-3-1-exceptions.md)
