Full Pseudocode Workbook
Full Pseudocode Workbook
Title: Pseudocode
• BE ABLE TO CONVERT PYTHON TO PSEUDOCODE
• BE ABLE TO CONVERT PSEUDOCODE TO PYTHON
• BE ABLE TO SOLVE PROBLEMS USING
PSEUDOCODE
Key Words: Pseudocode, Iteration, Selection.
Pseudocode
Pseudocode is not a programming language, it is a
simple way of describing a set of instructions that
does not have to use specific syntax.
Variables & assignments
• CONST PI 3.14
• name "Suffar"
• repeat True
• Temp -1.5
• Score 3
• Phonenumber "01911112000“
• Gender ‘M’
• Values with the string data type must be in
“Double Quotation mark".
• Chars will use ‘a single quote’
Input/output and declaration
Python:
Pseudocode:
DECLARE name : STRING
DECLARE num : INTEGER
OUTPUT "Enter a name“
INPUT name
Output "Enter a number"
INPUT num
OUTPUT "Hello", name
String Manipulation - Concatenation
You can also use , to join different data types
together (with a space).
Pseudocode:
DECLARE number : INTEGER
OUTPUT “Enter a number”
INPUT number
OUTPUT “The answer is” , number
Commenting on code
• Comments are used to explain lines of code to allow programmers to better
understand the code.
• Can be added at the top of a line of code or the side of a line of code.
• # in python
• // in pseudocode.
// finds the average of 2 numbers.
DECLARE num1 : INTEGER
DECLARE num2 : INTEGER
num1 5
num2 3
OUTPUT (num1+num2) / 2 //Displays the average
Starter tasks
• In pseudocode. A user wants to create a program to count the total cost of bananas.
Create a program that
• asks the user for the price of each banana such as 5.50
• Asks for the number of bananas bought such as 5.
• Outputs the total price in a full sentence.
Ensure all variables have been declared.
Write your code below:
Starter tasks
• In pseudocode. A user wants to create a program to calculate the width and length of a
rectangle.
The program will:
• Ask the user to input the length such as 7
• Ask the user to input the width – Such as 5
• Outputs the total area in a full sentence.
Ensure all variables have been declared.
Write your code below:
If statement
Python:
Pseudocode:
if name = "Alan" THEN
output "Hi Alan"
else
output "go away"
endif
If … then, elseif … then , else
Python:
Pseudocode:
if name = "Alan" then
OUTPUT "Hi Alan"
elseif name = "Sam" then
OUTPUT "Hi Sam"
else
OUTPUT "go away"
endif
If statement
Python:
Pseudocode:
DECLARE age : INTEGER
OUTPUT "Enter your age“
INPUT age
if age >= 13 AND age <=19 then What will the program
OUTPUT "Teenager" display if the user
elseif age = 11 OR age = 12 then enters 14?
• Teenager
OUTPUT "Tween"
else
OUTPUT "Invalid"
endif
Arithmetic operators
Complete the tasks
• Complete task 1-5
Task 1 – In Pseudocode
• In pseudocode, answer the following:
• Create a program that asks the user for firstname then surname.
• Display the answer in a full sentence.
Ensure all variables have been declared.
Write your code below:
Task 2 – In Pseudocode
• In pseudocode, answer the following:
• Ask the user for a 3 digit pin number. If the number is “007” then display “It’s BOND”.
Otherwise, display “boring”.
Ensure all variables have been declared.
Write your code below:
Task 3 – In Pseudocode
• In pseudocode, answer the following:
• Ask the user for a number. If the number is even, display “even”. If it’s odd, display
“Odd”.
Ensure all variables have been declared.
Write your code below:
Task 4 – In Pseudocode
• Ask the user for a number.
• If the number is between 1 and 9, display a positive 1 digit number.
• If the number is between 10 and 99, display a 2 digit positive number.
• If the number is 0 or 100, display “very close”.
• Otherwise, display incorrect.
Ensure all variables have been declared.
Write your code below:
Task5 – In Pseudocode
• Ask user to enter number of apples.
• Ask user to enter number of people who will share the apples evenly.
• If the number of people is greater than the number of apples, display error. Otherwise:
• Calculate and display how many apples each person will get (every person must get the exact
same number of apples).
• Calculate how many apples will remain.
• Add comments to your code to explain your code.
• Hint: you will have to use MOD / DIV for calculations and // for comments.
• ADD COMMENTS TO YOUR CODE
Ensure all variables have been declared.
Write your code below:
String Handling - Length
Python:
Pseudocode:
DECLARE name : STRING
name "Tom"
OUTPUT LENGTH(name)
Pseudocode:
DECLARE name : STRING
OUTPUT "Enter full name“
INPUT name
OUTPUT length(name)
What will the above code display if the user enters "Alex
Tom“
• 8 – Space counts as a character, so it displays 8 not
7.
String Handling - Substring
Python:
Pseudocode:
DECLARE name : STRING
name "Suffar"
OUTPUT substring(name,1,4)
Substring is used to extract part of a string. Both
of the above will display "Suff “
First index in PSEUDOCODE is 1
Substring in the exam (pseudocode)
Index 1 2 3 4 5 6 7
number
Character E N G L A N D
s
Substring in the exam (pseudocode)
What will the following code display?
country “United States "
OUTPUT( SUBSTRING(country,2,3) )
Characte U n i t e d S t a t e s
r
Substring in the exam (pseudocode)
What will the following code display?
country “United States "
OUTPUT( SUBSTRING(country,4,3) )
How many letters it will
Start position display
Characte U n i t e d S t a t e s
r
Substring in the exam (pseudocode)
What will the following code display?
country “United States "
OUTPUT( SUBSTRING(country,8,6) )
Pseudocode:
DECLARE name : STRING
name "Elizabeth"
OUTPUT UCASE(name)
OUTPUT LCASE(name)
The above code will display “ELIZABETH”
Then “elizabeth”.
Complete the tasks
• Complete task 6 to task 10
Task 6 – In Pseudocode
• Ask user to enter a name. If the name contains 4 letters or less,
display, your name “short and sweet” otherwise display, normal
name.
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 7 – In Pseudocode
• Ask the user for a game name that contains at least 6 characters.
• Output “Acceptable” or “Not acceptable” depending on the user’s answer.
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 8 – In Pseudocode
• Ask user for their school name.
• Display the first 3 characters of the school name.
• On a separate line display the 5th character of the school name.
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 9 – In Pseudocode
• Ask user for their favourite car model.
• Display the model name in uppercase then in lowercase on separate lines.
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 10 – In Pseudocode
• Ask user for firstname and surname.
• Concatenate the firstname with surname (without a space) and store it in a variable called total.
• Display the number of characters inside the variable total.
• Display the 3rd character in the variable total.
• Display the first 4 characters in the variable total.
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Case statement
CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
ENDCASE
The switch/case statement
• The switch/case statement is used if there are several possible options to be tested.
• It can be used instead of if, elseif , else.
• Programming construct: Selection.
CASE OF seasonOption
1: seasonName ← "Spring"
2: seasonName ← "Summer"
3: seasonName ← "Autumn"
4: seasonName ← "Winter"
OTHERWISE seasonName ← "Unknown"
ENDCASE
Pseudocode:
for x 🡨 1 to 10
OUTPUT x
next x
The code above will count from 1 to 10.
Count controlled loop (For loops)
Python:
Pseudocode:
for x 🡨 1 to 100
OUTPUT “hello”
next x
The code above will display “hello” 100
times.
Count controlled loop (For loops)
Python:
Pseudocode:
total 🡨 0
for x 🡨1 to 5
INPUT num
total 🡨 total+num
next x
The code above will calculate the total of 5 numbers.
Complete the tasks
• Complete task 15 to task 21
Task 15 – In Pseudocode
• Use a count controlled loop (for loop) to display “Welcome stranger” 100 times.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 16 – In Pseudocode
• Use a count controlled loop (for loop) to count from 1 to 1000.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 17 – In Pseudocode
• Use a count controlled loop (for loop) to ask the user for 10 numbers and add each number to the total.
• Display the total after every number that is entered.
• Display the average of the 10 numbers at the end.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 18 – In Pseudocode
• Use a count controlled loop (for loop) to ask the user for 20 numbers.
• Count and display how many of those numbers are above 100.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 19 – In Pseudocode
• Use a count controlled loop (for loop) to ask the user for 100 numbers.
• Count and display how many of those numbers are even and how many are odd.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 20 – In Pseudocode
• Use a count controlled loop (for loop) to ask the user for 1000 numbers.
• Count and display how many of those numbers are positive, negative and zeros.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 21 – In Pseudocode
• Use a count controlled loop (for loop) to count down from 1000 to 0.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Condition controlled loop (while loop)
Python:
Pseudocode:
total ← 0
WHILE total < 100 DO
OUTPUT "Enter number: "
INPUT num
total ← total + num
ENDWHILE
The above code will repeat until the total is greater than or equal to
100.
Condition controlled loop (while loop)
Python:
Pseudocode:
OUTPUT "Enter subject: "
INPUT subject
WHILE subject <> "CS" DO
OUTPUT "Incorrect"
OUTPUT "Enter subject: "
INPUT subject
ENDWHILE
OUTPUT "Correct"
Condition controlled loop (while loop)
Python:
Pseudocode:
repeat = True
while repeat DO
OUTPUT “Enter a number”
INPUT num
if num <100 THEN
repeat 🡨 False
endif
endwhile
The above code will loop until the user enters a number below 100.
Complete the tasks
• Complete task 22 to 25
Task 22 – In Pseudocode
• Ask user to enter username and password.
• If the username and password is correct, display “Logged in”
• Otherwise, display incorrect and repeat the questions.
• Assume the correct username is: “Computer” and the correct password is: “CS1234”
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 23 – In Pseudocode
• Ask user for a number then add it to a total that starts with 0.
• Repeat the above step until the total reaches 1000.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 24 – In Pseudocode
• Create a voting system for students to check how many students like school and how many don’t.
• Ask the user to vote “like” or “dislike”.
• Count and display and how many students entered like and how many entered dislike.
• Repeat the above until the user enters “STOP” when asked to enter a vote.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 25 – In Pseudocode
• Ask the user to enter a number.
• Repeat the above process until the user enters a negative number.
• Display the highest and lowest number entered once the user enters a negative number.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Condition controlled loop (do until)
The do until loop is not supported by Python.
Example:
REPEAT
OUTPUT “Enter your name”
INPUT name
until name = “Billie”
Condition controlled loop (do until)
Example:
total 🡨 0
REPEAT
OUTPUT “Enter a number”
INPUT num
total 🡨 total+num
until total > 100
RANDOM() * 10
This multiplies 0 by 10 and 1 by 10 to make it
RANDOM(0,10)
Random number generator
Python:
Pseudocode:
num 🡨 random() * 6
OUTPUT num
Pseudocode:
OPENFILE “teams.txt” FOR WRITE // Opens a text file in write mode
WRITEFILE “teams.txt” , “Aston Villa” // Writes aston villia in the file
CLOSEFILE “teams.txt” //Closes the text file.
File handling
Python:
Pseudocode:
DECLARE data : STRING
OPENFILE “teams.txt” FOR READ // Opens a text file in write mode
READFILE “teams.txt” , data // Writes aston villia in the file
Pseudocode:
DECLARE names : ARRAY[1:3] OF STRING
Names[1] 🡨 "Tom"
Names[2] 🡨 "Billy"
Names[3] 🡨 "Sam"
OUTPUT names[1]
What will the above code display?
• Tom
Arrays
Python:
Pseudocode:
DECLARE names : ARRAY[1:3] OF STRING
names[1] 🡨 “Adam” //Stores Adam on index 1.
Arrays
Python:
Pseudocode:
DECLARE names : ARRAY[1:3] OF STRING
for x 🡨 1 to 3
INPUT newname
names[x] 🡨 newname
next x
Empty array with 3 indexes is created and the arrays are
filled with 3 names that the user will enter.
2D Arrays
Python:
Pseudocode:
DECLARE position : ARRAY[1:2, 1:2] OF INTEGER
OUTPUT position[2,1]
Pseudocode:
DECLARE position : ARRAY[1:4, 1:2] OF INTEGER
for row 1 to 4
for column 1 to 2
OUTPUT position[row,column]
next column
next row
The code above will display all the numbers in the array.
Complete the tasks
• Complete task 38 to 43
Task 38 – In Pseudocode
• DECLARE an array called teachers and ask the user to input 3 teacher names then add them to the array.
• Display the name of the first teacher in the array.
• Array in pseudocode start with index 1.
ADD COMMENTS TO YOUR CODE
Write your code below:
Task 39 – In Pseudocode
• DECLARE an array called names that contains 3 indexes.
• Ask the user for a name.
• Add the name to the first index in the array.
ADD COMMENTS TO YOUR CODE
Write your code below:
Task 40 – In Pseudocode
• Declare an array called hobby that contains 5 indexes.
• Ask the user for 5 hobbies and add each hobby to a different index in the array.
ADD COMMENTS TO YOUR CODE
Write your code below:
Task 41 – In Pseudocode
• DECLARE an array called numbers that contains 5 different numbers.
• Use count controlled iteration to loop through the array and find and display the total of all numbers in the
array.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 42 – In Pseudocode
• names 🡨 [[34121,5],[23412,8],[10523,9]]
DECLARE the above array THEN
Calculate and output the average grades of each student. Hint: Use a loop to calculate (5+8+9).
The first number in each column indicates student exam number. So student 1 has an exam number of 34121 and grade of 5.
ADD COMMENTS TO YOUR CODE
Write your code below:
Task 43 – In Pseudocode
• Array coordinates = [ [5,2], [3,5], [7,5] ]
• DECLARE the above array.
• Use count controlled iteration to loop through the 2d array to calculate the total of all numbers in the array.
• Calculate the average of the numbers in the array.
• Hint: You must use a nested for loop.
• COMMENT ON YOUR CODE
Write your code below:
Functions and procedures
Python:
Pseudocode:
PROCEDURE games()
OUTPUT “Enter a game name”
INPUT choice
OUTPUT choice
ENDPROCEDURE
The code above creates a procedure called games that
asks for a game name and displays it on the screen.
Functions and procedures
Python:
Pseudocode:
PROCEDURE games(game1:STRING , game2:STRING)
OUTPUT "Top 1 game = ", game1
OUTPUT "Top 2 game = ", game2
ENDPROCEDURE
CALL games("fifa", "Overwatch")
Pseudocode:
PROCEDURE average(num1 : INTEGER ,num2 : INTEGER)
OUTPUT (num1+num2) / 2
ENDPROCEDURE
CALL average(5,7)
Functions and procedures
Python:
Pseudocode:
FUNCTION average(num1 : INTEGER, num2 : INTEGER) RETURNS REAL
avg 🡨 (num1+num2) / 2
RETURN avg
ENDFUNCTION
CALL average(5,7)
Functions and procedures
Python:
Pseudocode:
FUNCTION multiply(num1: INTEGER,num2: INTEGER) RETURNS INTEGER
mult 🡨 num1*num2
RETURN mult
ENDFUNCTION
CALL multiply(3,4)
Functions and procedures
Python:
Pseudocode:
FUNCTION total(num1:INTEGER,num2:INTEGER,num2:INTEGER) RETURNS
integer
tot = num1+num2+num3
RETURN tot
ENDFUNCTION
average 🡨 CALL total(3,2,1) / 3
The function is used to calculate the total, then we
calculate the average of the 3 numbers.
Complete the tasks
• Complete task 44 to 50
Task 44 – In Pseudocode
• Create a procedure called “sports” that asks the user for their favourite sport and displays it on the screen.
• COMMENT ON THE CODE
Write your code below:
Task 45 – In Pseudocode
• Create a procedure called “fullname” that takes in the user’s firstname and surname as parameter then
displays the full name. Use the following arguments: Bob, Suffar
• COMMENT ON YOUR CODE
Write your code below:
Task 46 – In Pseudocode
• Create a procedure called “division” that takes in 2 numbers as parameters. The procedure divides the first
number by the second number and displays the answer. Call your procedure with 20 and 2 as arguments.
• COMMENT ON YOUR CODE
Write your code below:
Task 47 – In Pseudocode
• Create a function called “highest” that takes in 2 numbers as parameters. It will then return the highest
number. Call the function with 6 and 8 as arguments.
• COMMENT ON YOUR CODE
Write your code below:
Task 48 – In Pseudocode
• Create a function called “over100” that takes in the total as a parameter. The first value of the total is 0.
• The function will repeatedly ask the user for a number, and adds it to the total until the total is above 100.
• The function returns the total once the total is above 100.
• COMMENT ON YOUR CODE
Write your code below:
Task 49 – In Pseudocode
• Create a function called “total” that takes in 4 numbers as parameter. The function calculates and returns the
total of the 4 numbers.
• THEN
• In the main program, create a variable called answer and store the total that is being returned by the function,
use 3 , 2, 6, 8 as arguments.
• THEN
• Calculate the average of the 4 numbers in the main program and display the answer.
• COMMENT ON YOUR CODE
Write your code below:
Task 50 – In Pseudocode
• Eatallyouwant restaurant charges an entry fee of £10 for children and £20 for adults.
• Create a function called “buffet” that takes in the number of adult and number of children as parameters.
• The function will then return the total price that needs to be paid.
• COMMENT ON YOUR CODE
Write your code below: