0% found this document useful (0 votes)
4 views7 pages

Computational Thinking

Uploaded by

kaylawendo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Computational Thinking

Uploaded by

kaylawendo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

COMPUTATIONAL THINKING

An algorithm is a sequence of steps or instructions to solve a problem.


An algorithm can be represented in a range of ways: it can be represented visually as a flowchart
or pseudocode.
A flowchart is a diagram showing the sequence of actions in a computer program; a graphical
representation to show the steps to solve a problem.
System flowchart symbols
Symbol Purpose
Used at the start and the end of the flowchart to signify the start and
the end
Used when data needs to be input and/or output from the program,
e.g. Input number 1

Used when something needs to happen, e.g. Add two numbers


together

Used to show the direction of flow, which is top to bottom and left to
right.
Used when a decision has to be made; the decision should be written
inside the diamond and there are two possible outcomes

A mini program inside a program that can be completed or repeated


when requested

1 of 7
Example of a flowchart where user inputs two numbers, adds them and outputs the result.

Pseudocode is a textual representation of an algorithm.


Pseudocode rules to follow in the way it is written
➢ All keywords (words used to describe a specific action e.g. INPUT) are written in capital
letters
➢ Each instruction has its own line
➢ All names given to data items and subroutines start with a capital letter
➢ Conditional and loop statements are indented by two spaces.

Pseudocode for an assignment statement


A value is assigned to an item/variable using the  operator. The variable on the left of the 
is assigned the value of the expression on the right. The expression on the right can be a single
value or several values combined with any of the mathematical operators.

Example of a pseudocode where user inputs two numbers, adds them and outputs the result.
OUTPUT “enter the two numbers”
INPUT number1
INPUT number2
Total number1 + number2
OUTPUT “The total of the two numbers is”, Total

2 of 7
SELECTION
➢ Selection is a programming construct with more than one possible pathway; a condition is
tested (using a question or criterion) before deciding which pathway to follow (the output)
➢ A condition is something that is checked to determine whether it is true or false
➢ Selection is achieved using IF statements.
➢ When using selection in any programming language, comparison operators are used to
compare values.
➢ Comparing different values gives programs the ability to determine whether something is
true or false and then decide which path to take next.
Flowchart example

3 of 7
Class activity
1. Write a pseudocode to match the flowchart algorithm above.
2. Complete the table below and add the variables and data types that will be required when
creating the program.
Variable name Data type

Adult FALSE
Cost  7.95
OUTPUT ("Enter the activity")
INPUT Activity
OUTPUT("Enter your age")
INPUT Age
IF Age >= 18
THEN
Adult  TRUE
ENDIF
IF Adult = TRUE
THEN
Cost  9.50
ENDIF
OUTPUT("As you are", Age, "it will cost you", Cost, "to go",
Activity)

4 of 7
CONDITIONAL OPERATOR
They are used to carry out comparisons between two values.
Operator What it means
= Equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
!= Not equal to

The keywords in selection are in uppercase – IF, THEN, ELSE, ENDIF


Conditional branching
This is sometimes referred to as selection. Conditional branching means that certain statements
are carried out depending on the value stored within a variable name.
There are two types:
1. IF…THEN
The syntax
IF <condition>
THEN
<statement or list of statements to be carried out>
ENDIF

2. IF…THEN…ELSE
The syntax
IF statements with an ELSE clause are written as follows:
IF <condition>
THEN
<statement or list of statements to be carried out>
ELSE
<alternative statement or list of alternative statements to be carried out>
ENDIF

5 of 7
3. Nested IF statement
This is an IF condition within another IF.
With an IF statement we follow the THEN part when the IF statement is true but we only follow
the ELSE part if the IF statement is false.
Example
Consider marks of 34, 45, 62 and 78.

Always make sure that the number of ENDIFs matches the number of IFs and that they are
indented to match. Always make sure the ELSEs are in line with the THENs.

6 of 7
Class activity
Write a pseudocode for the following flowchart

7 of 7

You might also like