0% found this document useful (0 votes)
50 views108 pages

Full Pseudocode Workbook

The document provides a comprehensive guide on pseudocode, including its conversion to and from Python, problem-solving techniques, and various programming concepts such as variables, input/output, string manipulation, control structures (if statements, case statements), and loops (for and while). It includes examples and starter tasks for practice, emphasizing the importance of comments in code for clarity. The document serves as a foundational resource for understanding and using pseudocode in programming.

Uploaded by

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

Full Pseudocode Workbook

The document provides a comprehensive guide on pseudocode, including its conversion to and from Python, problem-solving techniques, and various programming concepts such as variables, input/output, string manipulation, control structures (if statements, case statements), and loops (for and while). It includes examples and starter tasks for practice, emphasizing the importance of comments in code for clarity. The document serves as a foundational resource for understanding and using pseudocode in programming.

Uploaded by

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

Lesson Objectives

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)

The Length function is used to find the number


of characters in a string.
String Handling - Length
Python:

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)

The following code will display: " LAND "


Country  "ENGLAND "
output(SUBSTRING(country,4,4) )
How many letters it will
Start position display

• Substrings start from 1. So (4,4) means it starts with


the letter L “index 4”, it displays L and 3 more letters
for a total of 4 letters.
Index 1 2 3 4 5 6 7
number
Character E N G L A N D
s
Substring in the exam (pseudocode)
The following code will display: " GLA "
country  "ENGLAND "
OUTPUT(SUBSTRING(country,3,3) )
How many letters it will
Start position display

• (3,3) means it starts with the letter G “index 3”, it


displays L and 2 more letters for a total of 3 letters.

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) )

How many letters it will


Start position display

It will display “nit”


Index 1 2 3 4 5 6 7 8 9 10 1 12 1
number 1 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

It will display “ted”


Index 1 2 3 4 5 6 7 8 9 1 11 12 1
number 0 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,8,6) )

How many letters it will


Start position display

It will display “States”


String Handling – Upper & Lower
Python:

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.

OUTPUT “Enter number 1, 2 or 3”


INPUT option
CASE OF option
1: OUTPUT “High”
2: OUTPUT “Low”
3: OUTPUT “Medium”
OTHERWISE OUTPUT “Wrong option”
ENDCASE
The switch/case statement
OUTPUT "Please select a season: (1 for Spring, 2 for Summer, 3 for Autumn, 4 for Winter)"
INPUT seasonOption

CASE OF seasonOption
1: seasonName ← "Spring"
2: seasonName ← "Summer"
3: seasonName ← "Autumn"
4: seasonName ← "Winter"
OTHERWISE seasonName ← "Unknown"
ENDCASE

OUTPUT "You've selected " , seasonName


The switch/case statement
DECLARE fruitOption : CHAR
OUTPUT "Please select a fruit: (A for Apple, B for Banana, O for Orange)"
INPUT fruitOption
CASE OF fruitOption
"A": fruitName ← "Apple"
"B": fruitName ← "Banana"
"O": fruitName ← "Orange"
OTHERWISE fruitName ← "Unknown"
ENDCASE

OUTPUT "You've selected " , fruitName


Complete the tasks
• Complete task 12 to task 14
Task 12 – In Pseudocode
• Use case statement 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)
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 13 – In Pseudocode
• Use case statement 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”.
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 14 – In Pseudocode
• Use case statement 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.
• Ensure all variables have been declared.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Count controlled loop (For loops)
Python:

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

• The above will repeat until the total is above 100.


Condition controlled loop (do until)
Example:
count 🡨 0
REPEAT
num = input(“Enter a number”)
if num > 100 then
count 🡨 count + 1
until num = 0

• The above program will count how many numbers


entered are above 100. It will stop when the number
0 is entered.
Complete the tasks
• Complete task 26 to 30
Task 26 – In Pseudocode
• Ask the user for their age.
• Display “you are an adult” when the user enter 18 or above.
• Repeat the above process until the user enters 18 or above.
• Use a do until loop for the iteration.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 27 – In Pseudocode
• Ask the user for their favourite subject.
• Display “correct” when the user enters “Computer Science”.
• Repeat the above process until the user enters “Computer Science”.
• Use a do until loop for the iteration.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 28 – In Pseudocode
• Ask the user to enter a number then add it to a total.
• Repeat the above process until the total is above 1000.
• Use a do until loop for the iteration.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 29 – In Pseudocode
• A teacher wants to count the number of students who play games for at least 10 hours a week.
Create an algorithm that:
• Ask 30 students for the number of hours a week they spend playing games.
• Count and display the number of students who play games for at least 10 hours a week.
• Use a do until loop for the iteration.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 30 – In Pseudocode
• Ask the user to enter 10 numbers.
• Count and display how many of the numbers entered are between 10 and 99.
• Use a do until loop for the iteration.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Random number generator
RANDOM() function generates a random decimal number
between 0 and 1.

To generate a random number between 0 and 10 we do


the following.

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

The above code will generate a random number between


0 and 6 inclusive.
Complete the tasks
• Complete task 31 to 32
Task 31 – In Pseudocode
• Use a count controlled loop to display 10 random numbers that are between 0 and 100 inclusive.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 32 – In Pseudocode
• Generate a random number between 0 and 3
• Ask the user to guess the random number.
• Display whether they guessed it correctly or incorrectly.
• ADD COMMENTS TO YOUR CODE
Write your code below:
File handling
Python:

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

CLOSEFILE “teams.txt” //Closes the text file.


Complete the tasks
• Complete task 33 to 37
Task 33 – In Pseudocode
• Create a text file called “names.txt”
• Open the text file
• Ask the user for a name.
• Write the name in the text file.
• Close the text file.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 34 – In Pseudocode
• Create a text file called “numbers.txt”
• Open the text file
• Ask the user for 10 numbers using count controlled iteration.
• Check if the number is bigger than 100. If it is, then add the number to the text file.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 35 – In Pseudocode
• Create a text file called “evennumbers.txt”
• Open the text file
• Ask the user to enter an even number.
• If the number is even add it to the text file.
• Otherwise, ask the user to enter the number again. Ask for a number repeatedly until the user enters an even
number.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 36 – In Pseudocode
• Open a text file called “teachers.txt”
• Read the file and display it on screen
• Close the file.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Task 37 – In Pseudocode
• Open a text file called “cars.txt”
• Ask the user if they want to read the text file.
• If the user enters “yes”, read and display all the contents of the text file.
• Otherwise, display “Good Bye”.
• ADD COMMENTS TO YOUR CODE
Write your code below:
Arrays
Python:

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]

What will the above code display?


• 3
2D Arrays
Python:

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")

Creates a procedure called games with 2 parameters.


Functions and procedures
Python:

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:

You might also like