Professional Documents
Culture Documents
01 Outputs, Inputs and Variables
01 Outputs, Inputs and Variables
com CSUK:Teacher
Quick Reference
Construct Setup Example
Variables
Assignment Label Value x 10
name ‘Sam’
Constants CONSTANT LABEL Value CONSTANT PI 3.14
Input/Output
Input USERINPUT name USERINPUT
Output OUTPUT OUTPUT ‘Your name is ’ + name
Outputs
An output is where a program will display some information on the screen for the user. When writing algorithms, we
can demonstrate an output using an OUTPUT statement. The data that we enter after the keyword OUTPUT, will be
outputted to the screen.
For example, if we wished to write an algorithm for a program that outputs the statement “Hello World” to the screen,
we could write:
But what is important to recognise is that if we wish our programs to store the inputted data, we must assign our input
statement to a variable.
What is a variable?
A variable is a named location in memory, which can store data whilst the program is running. In other words, it’s a
word which represents a place that can store a single item of data that is assigned to it.
So, if we wished to write an algorithm for a program that asks the user for their name, stores the inputted name and
outputs both a ‘hardcoded’ message and the contents of the variable, we could write:
Write an algorithm which will ask the user to enter their name, and then respond with the
statement: ”The name *name* is a beautiful name”.
Computer Science UK Membership Site Licence: Do not share outside of your centre 1
ComputerScienceUK.com CSUK:Teacher
Let’s begin by breaking down the question to understand what it wants us to do.
Ultimately, there are two parts to this algorithm question:
1. User to enter name
2. Sentence (including inputted name) to be outputted.
Point 1, requires us to write an input statement. This can be achieved by the following:
This line represents the displaying of the text ‘Enter your name’ on the screen and waiting for a user’s response.
However, because point 2 requires the inputted name to be outputted, we need to have a way to store the input, so that
it can be later outputted. We can demonstrate this by assigning a variable to the USERINPUT statement. In the example
below, we have assigned a variable called name to the USERINPUT statement.
Now let’s focus on point 2. This part of the question requires that we output some text (which has the data type known
as ‘string’) along with the contents of a variable. The OUTPUT statement can allow us to output, and the + operator can
allow us to join together strings and variables. We must remember to write strings with quotes and variables without.
Here is an example:
Question 1 Algorithm
Write an algorithm that asks the user to enter
their favourite colour, then outputs the
sentence “Your favourite colour is *colour*”
(where *colour* is the inputted string).
Question 2 Algorithm
Write an algorithm that asks the user to enter
their first name, middle name and surname,
stores each input in separate variables, then
outputs the user’s full name.
Question 3 Algorithm
Write an algorithm that asks the user to enter
their house name/number, street name, town
and postcode, then outputs the user’s full
address back to the screen.
Computer Science UK Membership Site Licence: Do not share outside of your centre 3