Lesson Objectives
To buy full version with all of the GCSE Computer
Science topics click on the link below:
• https://www.tes.com/teaching-resource/resour
ce-12657187
Lesson Objectives
• Title: Pseudocode
• Big Question: Be able to follow pseudocode
algorithms.
• Small Questions: Code using pseudocode. Follow
pseudocode trace tables.
• Key Words: Pseudocode, Iteration, Selection.
Pseudocode
Pseudocode is not a programming language, it is a
way of describing instructions. It does not have
specific syntax, however, you will be coding
Pseudocode using OCR Exam Reference Language
which does have specific syntax.
Variables & Constants
• CONST PI = 3.14
• name = "Suffar"
• repeat = True
• Temp = -1.5
• Score = 3
• Phonenumber = "01911112000“
• global name = “Sarah”
• Values with the string data type must be in
"Quotation mark".
Input/output
Python:
Pseudocode:
name = input("Enter a name")
num = input("Enter a number")
print(num)
print("Hello " + name)
Input & output are exactly the same in python/pseudocode with
1 difference. In Pseudocode, you don’t have to state the data
type for integer/float.
String Manipulation - Concatenation
We use the + to join strings together (without a
space).
You can also use , to join different data types
together (with a space).
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.
num1 = 5
num2 = 3
print((num1+num2) / 2) //Displays the average
If statement
Python:
Pseudocode:
if name == "Alan" then
print("Hi Alan")
else
print("go away")
endif
If … then, elseif … then , else
Python:
Pseudocode:
if name == "Alan" then
print("Hi Alan")
elseif name == "Sam" then
print("Hi Sam")
else
print("go away")
endif
If statement
Python:
Pseudocode:
age = input("Enter your age")
if age >= 13 AND age <=19 then
What will the program
print("Teenager") display if the user
elseif age == 11 OR age == 12 then enters 14?
• Teenager
print("Tween")
else
print("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.
• Use concatenation “+” to display the answer in a full sentence.
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”.
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”.
Write your code below:
Task 4 – In Pseudocode
• Ask the user for a number.
• If the number is between 1 and 9, display “The number is a positive 1 digit number”.
• If the number is between 10 and 99, display “The number is a 2 digit positive number.”
• If the number is 0 or 100, display “very close”.
• Otherwise, display incorrect.
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.
Write your code below:
Casting
Casting is when you change the data type from one to
another.
Example
• str(525) - Converts integer to string.
• int("28") - Converts string to integer.
• float("3.22") - Converts String to Float.
• real("2.77") - Converts String to Real.
• bool("False") - Converts String to Boolean.
// Casting the variable choice from String to Boolean.
choice = input("Enter True or False")
Bool(choice)
String Handling - Length
Python:
Pseudocode:
name = "Tom"
print(name.length)
The Length function is used to find the
number of characters in a string.
String Handling - Length
Python:
Pseudocode:
name = input("Enter full name")
print(name.length)
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:
name = "Suffar"
print(name.substring(0,4))
Substring is used to extract part of a string.
Both of the above will display "Suff "
String Handling - Substring
String Handling - Substring
String Handling - Substring
It will display “nit”
String Handling - Substring
It will display “states”
String Handling - Substring
hobby = “basketball”
print( hobby.left(6) ) // this will display basket
print( hobby.right(4) ) // this will display ball
What will the following code display?
mode = “Ultimate Team”
print( mode.left(3) )
print( mode.right(4) )
• Ult
• Team
String Handling – Upper & Lower
Python:
Pseudocode:
name = "Elizabeth"
print( name.upper )
print( name.lower )
The above code will display “ELIZABETH”
Then “elizabeth”.
String Handling – ASCII Conversion
Python:
Pseudocode:
print(ASC(A)) // displays numerical value of A “65”
print(CHR(98)) // displays the character “b”
The above uses the ASCII table values to change a
letter to its character code or vice versa.
Complete the tasks
• Complete task 6 to task 11
Task 6 – In Pseudocode
• Ask user whether they are a child and ask them to answer the
question with True or False.
• Cast the data type from string to Boolean.
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.
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 last 2 characters of the school name.
• On a separate line display the 5th character of the school name.
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.
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.
• Display the last 2 characters in the variable total.
Write your code below:
Task 11 – In Pseudocode
• Display the numerical value for the character B
• Then display the character for the value 68.
Write your code below:
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.
option = input(“Enter option 1 for high, 2 for low, 3 for medium”)
switch option:
case 1:
print (“High”)
case 2:
print (“Low”)
case 3:
print (“Medium”)
default:
print(“Wrong option”)
endswitch
The switch/case statement
game = input(“Enter a game name”)
switch game:
case “Overwatch”:
print (“FPS”)
case “FIFA”:
print (“Ultimate Team”)
case “League Of Legends”:
print (“MOBA”)
default:
print(“Unknown”)
endswitch
Complete the tasks
• Complete task 12 to task 14
Task 12 – In Pseudocode
• Use switch case to solve the following algorithm.
• Ask user for arithmetic operator – “add”, “subtract”,”multiply”,”divide”.
• Ask user for 2 numbers and store them in separate variables.
• Display the correct answer depending on what the user picks – Example: If the user types multiply, multiply the
2 numbers together.
• Display “WRONG CHOICE” for any other option other than (add,subtract,multiply,divide)
Write your code below:
Task 13 – In Pseudocode
• Use switch case to solve the following algorithm.
• Ask the user to enter the number 100 or the number 1000.
• If the user enters 100, display “correct”, if the user enters 1000, display “almost”, otherwise display “wrong
choice”.
Write your code below:
Task 14 – In Pseudocode
• Use switch case to solve the following algorithm.
• Ask the user to enter a team name.
• If the user enters Liverpool, display “red”, if the user enters Chelsea, display “Blue”.
• Display “incorrect” for any other choice.
Write your code below: