Designing, creating and refining algorithms
Input Process Output
Framework for Identifying Input, Process, Output
Read the Scenario Carefully:
- Understand the context and objectives of the scenario.
- Identify any specific tasks or actions mentioned.
Identify Inputs:
- Look for any data or information that needs to be provided or collected.
- Inputs are usually given or required by the user or environment.
Tips: Input
Common words that help you identify input
- Prompt
- Asks
- Input
Your input will also provide a prompt (output message) for the user
- Initalise all your input variables at the start
age = input("What is your Age?: ")
day = input("Is it Saturday?: ")
ticket = input("Do you have a ticket?: ")
Tips: Set a Count
Look for words that identify a counter
- the program counts each entry
- outputs the number of people who entered the ride
declare and initialise a count variable to 0 before any processing takes place
count=0
Tips: Set a Total
Look for words that identify a total
- the program keeps a total of the score
- the program outputs the total cost
declare and initialise a total variable to 0 before any processing takes place
total=0
Tips: Be aware of subroutines
Exam questions sometimes say
a function/procedure takes in 3 values
This is not asking for input, it is asking for arguments to be passed into the parameters. This will make more sense when you get to Sub-routines
Identify Processes:
Determine the steps or actions taken to achieve the objective. Processes often involve calculations, decisions, or manipulations of the input data.
- Your inputs will likely be part of the condition for process
- The question will say something that will provide you with the construct to use
Tips: Selection
Look for words that suggest selection
- the user can select if they are happy or not
- the user will choose the car that they want
keywords to look for are
- if
- choose
or anything that implies a user is choosing an option
Tips: While Loop
Look for words that suggest a while loop
- the program repeats until the user inputs -1
- the user is able to input values until the total is above 100
keywords to look for are
- repeat
- until
or anything that implies it needs to happen more than once
Tips: For Loop
Look for words that suggest a for loop, a for loop will run for a set number of iterations. So look for something that suggests it should run a certain number of times
- the user is able to input 10 values
- 8 people are able to join the ride
- there are 25 students who completed a test
keywords to look for are
- numbers
or anything that implies it needs to happen a set number of times that is based on a number
# set total to 0
total = 0
# loop 25 times for each student
for i in range(25):
# this will take in 25 student scores
score = input("input the students score: ")
# it also keeps a running total of the scores
total = total + score
# calculate the average after the loop
average = total/25
# output the average
print("Average score:")
print(average)
Tips: Implementing a Count
If there is a count then
count = 0 #at the start of your program
- A count will need some form of loop, usually a while loop
while day != "saturday":
# carry out the other processing identified
count = count+1 #in your loop update the count variable
# update your condition variable
Tips: Implementing a Total
If there is a count then
total = 0 #at the start of your program
- A total will need some form of loop, usually a while loop
while numberBought != -1:
# carry out the other processing identified
#in your loop update the count variable
total = total + numberBought
# update your condition variable
numberBought=input("Input numberBought or -1 to exit")
Identify Outputs:
Look for the results or information produced by the processes. Outputs are the outcomes or feedback provided to the user or environment.
Tips: Identifying Outputs
Look for words that suggest output
- the program tells the user if they are able to enter
- the program outputs the total cost
keywords to look for are
- output
- tells
- confirms
or anything that implies the user will get some feedback
A worked example from an OCR Exam Question
Scenario:
OCR Land is a theme park aimed at children and adults. Entrance tickets are sold online. An adult ticket to OCR Land costs £19.99, with a child ticket costing £8.99. A booking fee of £2.50 is added to all orders.
One ride in OCR Land has a minimum height of 140 cm to ride alone or 120 cm to ride with an adult.
Create an algorithm that:
- Asks the user to input the height of the rider, in centimetres.
- If needed, asks if they are riding with an adult.
- Outputs whether or not they are allowed to ride.
- Repeats this process until 8 people have been allowed to ride.
Identifying Inputs, Processes, and Outputs
Inputs:
- Height of the rider (in centimetres).
- Whether the rider is riding with an adult (if needed).
Processes:
- Check the height of the rider.
- Determine if the height is sufficient to ride alone or if an adult is needed.
- Decide if the rider meets the height requirement to ride alone (140 cm) or with an adult (120 cm).
- Repeat until 8 people have been accepted on the ride
- notice that question looks like it is a for loop but it is counting how many have been accepted and therefore this repeat is actually a while loop *
Outputs:
- Inform the user whether they are allowed to ride or not.
Example in Practice
Let's apply this to the algorithm creation process:
Algorithm Steps:
Initialize a counter for the number of riders allowed to ride.
While the number of riders allowed to ride is less than 8:
- Ask the user to input the height of the rider in centimetres (Input).
- If the height is less than 140 cm, ask if they are riding with an adult (Input).
- If the height is 140 cm or more, allow the rider to ride (Output).
- If the height is between 120 cm and 139 cm, check if they are riding with an adult (Process).
- If riding with an adult, allow the rider to ride (Output).
- If not riding with an adult, do not allow the rider to ride (Output).
- If the height is less than 120 cm, do not allow the rider to ride (Output).
- Increment the counter for riders allowed to ride (Process).
Example PseudoCode
This approach follows the system above where you identify the inputs and set them at the start. You then need to make sure you take them in again within the end of the loop so that the next rider is able to be checked.
# set the counter for the riders allowed through
riders_allowed = 0
# take the input of the height for first rider
height = int(input("Enter the height of the rider in cm: "))
# input if they are with an adult for first rider
with_adult = input("Are you riding with an adult? (yes/no): ")
# loop until 8 riders have been allowed through
while riders_allowed < 8:
# check height is allowed
if height >= 140:
print("Allowed to ride")
# if it is add the rider and then rebegin the loop
riders_allowed += 1
# if they are less than 140 then check they are with an adult
elif 120 <= height < 140:
#if they are then increment the counter and loop
if with_adult == "yes":
print("Allowed to ride")
riders_allowed += 1
else:
# if not then output rejection and loop
print("Not allowed to ride")
else:
# this will capture if height is less than 120
# if it is they are not allowed to ride
# reject and loop again
print("Not allowed to ride")
# take the input of the height for next rider
height = int(input("Enter the height of the rider in cm: "))
# input if they are with an adult for next rider
with_adult = input("Are you riding with an adult? (yes/no): ")
Refined Example PseudoCode
The previous approach was not the most efficient however, although it would be awarded full marks in an exam. In this case (when you get comfortable) you can take the inputs within the loop itself at an appropriate point.
- There isn't a need to check if someone has an adult with them if they are already tall enough.
- The height can be taken when first entering the loop also
# set the counter for the riders allowed through
riders_allowed = 0
# loop until 8 riders have been allowed through
while riders_allowed < 8:
# take the input of the height
height = int(input("Enter the height of the rider in cm: "))
# check height is allowed
if height >= 140:
print("Allowed to ride")
# if it is add the rider and then rebegin the loop
riders_allowed += 1
# if they are less than 140 then check they are with an adult
elif 120 <= height < 140:
# input if they are with an adult
with_adult = input("Are you riding with an adult? (yes/no): ")
#if they are then increment the counter and loop
if with_adult == "yes":
print("Allowed to ride")
riders_allowed += 1
else:
# if not then output rejection and loop
print("Not allowed to ride")
else:
# this will capture if height is less than 120
# if it is they are not allowed to ride
# reject and loop again
print("Not allowed to ride")
Enough to get by:
Tips: You Don't Need Perfection
Although it might seem you need a perfect solution you can still get full marks with the previous solutoin
- you are not measured on efficiency in GCSE
You can often get a grade 5 (50% approx) in a long marker by
- identifying the correct inputs
- identify the correct construct
- identifying the correct condition for the construct
- outputting the result
The response below would still get you at least 2 marks possibly 3 (grade 4)
# set the counter for the riders allowed through
riders_allowed = 0
# take the input of the height for first rider
height = int(input("Enter the height of the rider in cm: "))
# input if they are with an adult for first rider
with_adult = input("Are you riding with an adult? (yes/no): ")
# loop until 8 riders have been allowed through
while riders_allowed < 8:
print("allowed to ride")
riders_allowed = riders_allowed + 1
# take the input of the height for next rider
height = int(input("Enter the height of the rider in cm: "))
# input if they are with an adult for next rider
with_adult = input("Are you riding with an adult? (yes/no): ")