Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

ComputerScienceUK.

com CSUK:Teacher

Outputs, Inputs and Variables

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:

OUTPUT ‘Hello World’

Inputs and Variables


An input is where a program will ask the user to enter some data. When writing algorithms, we can demonstrate this
using a USERINPUT statement.

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:

OUTPUT ‘What is your name?’


name  USERINPUT
OUTPUT ‘Your name is:’
OUTPUT name

Algorithm Writing Guidance - Outputs, Inputs and Variables


Consider the following algorithm question:

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:

OUTPUT ‘Enter your name:’


USERINPUT

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.

OUTPUT ‘Enter your name:’


name  USERINPUT

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:

OUTPUT ‘The name ’ + name + ‘ is a beautiful name’)

So, putting it all together, a solution to this question is:

OUTPUT ‘Enter your name:’


name  USERINPUT
OUTPUT ‘The name ’ + name + ‘ is a beautiful name’)

Practice Questions – Outputs, Inputs & Variables


Worked Example
Write an algorithm that will ask the user to enter their star sign, then output the sentence “Your star sign has been
recorded as *star_sign*”.
Output statement displays a message to user asking them
Variable assigned to input statement to to enter star sign.
store user’s input

OUTPUT ‘Enter your star sign:’


star_sign  USERINPUT
OUTPUT
Computer Science UK Membership ‘Your
Site Licence: star
Do not signofhas
share outside been recorded as’ + star_sign
your centre 2
ComputerScienceUK.com CSUK:Teacher

Output statement outputs a string (some text) joined to


the contents of the variable.

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

You might also like