video

Lesson video

In progress...

Loading...

Hello, my name is Mrs. Holborow and welcome to Computing.

I'm so pleased you decided to join me for the lesson today.

Today we are going to be looking at pseudocode.

We will compare pseudocode with programming languages and learn how to represent an algorithm with pseudocode.

Welcome to today's lesson from the unit, algorithms. This lesson is called representing algorithms using pseudocode, and by the end of today's lesson, you'll be able to represent an algorithm using pseudocode.

Shall we make a start? We will be exploring these keywords throughout today's lesson.

Pseudocode.

Pseudocode, a way of expressing an algorithm that is independent of a specific programming language.

Translate.

Translate, to convert something from one form to another, making it understandable or usable in a different context.

Watch out for these key words during today's lesson.

Today's lesson is broken down into two parts.

We'll start by comparing pseudocode with programming languages.

Then we'll represent algorithms with pseudocode.

Let's make a start with the first part of today's lesson, where we are going to compare pseudocode with programming languages.

Look at the statements below.

Can you rearrange them into a logical order to make a margarita pizza? So here's the statements.

Sprinkle fresh basil leaves on top of the cheese.

Let it cool, cut into pieces and share it with your friends.

Break up the cheese and spread it on top of the sauce.

Collect the dough, sauce, cheese, and fresh basil leaves.

Take the pizza outta the oven carefully, using oven gloves.

Place the pizza in the oven and bake at 200 degrees Celsius.

Roll out the pizza dough and spread sauce evenly on the top.

Can you put those items into the correct order? Maybe pause the video whilst you have a think.

There are many ways to make a pizza.

Here is one way.

So collect the dough, sauce, cheese, and fresh basil leaves.

Roll out the pizza dough and spread sauce evenly on the top.

Break up the cheese and spread it on top of the sauce.

Sprinkle fresh basil leaves on top of the cheese.

Place the pizza in the oven and bake at 200 degrees Celsius.

Take the pizza outta the oven carefully, using oven gloves, and then let it cool, cut into pieces and share with your friends.

The recipe to make a pizza is an example of an algorithm.

Algorithms can be represented in many different ways, such as written descriptions, flow charts, and pseudocode.

There is no one best method to express an algorithm.

The best method to use will depend on the problem being solved.

The word pseudocode may seem a bit challenging, but let's break it down into two parts, pseudo and code.

Pseudo means pretend or fake.

Code refers to the instructions written in a programming language.

So the word pseudocode literally means pretend code.

Unlike flowcharts, there are no set standards or conventions that must be used for pseudocode.

This means that the style and conventions used for pseudocode may differ for each GCSE exam board.

Whatever style of pseudocode is used, it is important to be consistent and make sure that the meaning is clear.

When writing pseudocode, keywords are often capitalised.

For example, INPUT, PRINT, WHILE, FOR, and IF, THEN and ELSE.

Note, there are many other keywords that are used in pseudocode.

These are just some examples.

Pseudocode keywords may look different to real programming languages, but the intended logic is the same.

For example, here's a bit of pseudo code where we have user_name is equal to INPUT in capital letters, and then we have open and closed brackets.

INPUT is where a user is expected to input something.

Here's another pseudo code application.

So we have the word PRINT, all in capital letters, and then we have open brackets with the word welcome inside speech marks, and then we have our closed bracket.

PRINT, information will be output to the screen.

Here's another example.

WHILE, all in capital letters, password_guess, exclamation mark equals, which is not equals, password.

Here the WHILE starts an iteration, as long as the condition is met.

So in this case, as long as the password guess is not equal to password.

Here's another example, FOR.

For count equals 1 to 5.

Notice the capital letters for FOR and TO.

FOR shows a count controlled iteration.

Do something a set number of times.

Here's another example with some selection statements.

So we have IF hour is less than 12, THEN PRINT, "Good morning," ELSE PRINT, "Good afternoon," ENDIF.

IF-THEN-ELSE shows a selection decision.

True or false? Unlike flowcharts, there are no set standards or conventions that must be used for pseudocode.

Pause the video whilst you have a think.

That's right, this statement is true.

There are no set standards or conventions for pseudocode.

Remember, that whatever style of pseudocode is used, it is important to be consistent and make sure that the meaning is clear.

Pseudocode is a way of representing an algorithm using syntax that is independent of any particular programming language.

Programmers use pseudocode in a similar way as artists use sketches.

It is a quick and easy alternative to writing a whole programme in order to test a solution.

Pseudocode is often used to see if a solution is possible and logical, before translating it into a final programme.

It is important to note that although pseudocode may look like real programming code, it cannot be directly executed by a computer.

Pseudocode must be translated into a real programming language such as Python, Java, or C#, for it to be executed by a computer.

There are several reasons to represent algorithms as pseudocode, such as, it uses clear and concise language, which is close to English.

It's not tied to a particular programming language.

It helps to spot and fix errors, and it can act as a blueprint and rough guide for final code.

True or false, pseudocode can be executed by a computer.

This is false.

Pseudocode must be translated into a real programming language such as Python, Java, or C#, for it to be executed by a computer.

Time to check your understanding.

The word pseudocode literally means, A, code that a computer can understand, B, pretend or fake code, or C, code that a human can understand.

Pause the video whilst you have a think.

That's right, B, the word pseudocode literally means pretend or fake code.

Okay, we've come to the first set of tasks for today's lesson.

You are doing a fantastic job so far, so well done.

For part one, write two or three sentences to describe why pseudocode is not the same as code written in a programming language.

Then for part two, write two reasons why a programmer may choose to create an algorithm in pseudocode.

Pause the video whilst you answer the questions.

How did you get on? Great work.

Sam here has a sample answer.

"Pseudocode literally means pretend code.

This means it might look like real code, but a computer cannot directly use it to follow instructions.

Also, pseudocode has no strict syntax rules, whereas a programming language has very strict syntax rules.

A programmer will translate the logic of the pseudocode into a specific language that a computer can use, such as Python." Well done, Sam.

That's a really comprehensive answer.

Well done.

For part two, you were asked to provide two reasons why a programmer may choose to create an algorithm in pseudocode.

Here's another sample answer from Sam.

"A programmer might use pseudocode to help make a complex algorithm easier to understand and fix errors.

Also, if a programmer created an algorithm in pseudocode, they would be able to translate the pseudocode into lots of different programming languages." There's a great couple of reasons there.

Well done, Sam.

Remember, if you've got stuck or need to add some extra detail to your answers, you can always pause the video, or go back a couple of slides and improve your answers.

Okay, we are now moving on to the second part of today's lesson, and you've done a great job so far, so, well done.

We are now going to look at how we can represent algorithms using pseudocode.

Izzy and Sam are discussing pseudocode.

Izzy says, "I think that programmers should always use pseudocode before writing a computer programme for an algorithm." Sam says, "I think it might not always be necessary to write pseudocode before writing a computer programme for an algorithm." Which statement do you agree with? Perhaps pause the video whilst you have a quick think.

Sam is actually correct For very straightforward tasks, writing pseudocode might not be necessary, as the code itself might be clear enough.

Experienced programmers may also already have a strong grasp of an algorithm.

Pseudocode is an effective way to represent algorithms, because only the basic knowledge of programming is needed to read, write and understand the logic.

Before attempting to represent an algorithm with pseudocode, it's first important to understand the problem that needs to be solved.

Pseudocode can be used to represent the algorithm for calculating the cost of 3D modelling software.

Look at the written description below.

Izzy sells 3D modelling software to businesses.

She charges her customers five pounds per month for each user of her design software.

Customers also have to pay tax, VAT, of 20% on each user licence.

She would like to work out the total monthly cost for each customer, so she can send them a bill.

Maybe reread this description carefully, so you fully understand the system.

How would you describe the problem to be solved in one sentence? Maybe pause the video whilst you have a think.

Ah, Sam's got a solution here.

<v ->"I think the problem is to calculate</v> the total monthly cost for each of Izzy's customer." Abstracting the most important information from the description will make creating the algorithm easier.

So let's see if we can do that now.

What pieces of information do you think are most important to create an algorithm to solve a problem? Maybe pause the video whilst you have a think.

How did you get on? Here are some key bits of information that I've abstracted from the problem.

Customers are charged five pounds per month for each user.

They have to pay tax or VAT of 20% on each user licence, and the total monthly cost for each customer needs to be calculated.

Sam says, "I think I understand the problem and have enough information to create an algorithm in pseudocode." There are many different ways to represent algorithms in pseudocode.

In most cases, it's sensible to break down algorithms into smaller, more manageable steps.

Remember this is called decomposition.

Sam says, "First, I would define the cost of a licence and the rate of VAT as constants at the top of the pseudocode." That's a good idea as a start, Sam.

Well done.

So here we have the pseudocode.

We have license_cost is equal to five, and then we have vat_rate is equal to 0.

2.

Remember, that's 20%.

A constant is a value that cannot be changed once the programme is running, it's a fixed value.

Sam says, "I would then create a function called, calculate_monthly_bill, that has a parameter called number_users." Let's see the pseudocode for this.

So we now have a FUNCTION which is called calculate_monthly_bill, and we are passing the parameter of number of users in the brackets.

Sam says, "Then I would write the code to calculate the licence fee, VAT and the total inside the function." Let's have a look at the pseudocode now.

So inside the FUNCTION we have license_fee is equal to number of users times license_cost.

So that's gonna be the number of users multiplied by five.

We then have that is equal to licence fee multiplied by VAT_rate.

And then lastly, we have total_cost is equal to license_fee plus VAT.

Sam says, "Finally, I would return the total cost at the end of the function." So you can see here on line nine of the pseudocode, we have RETURN total_cost, and then we've ended the function on line 11.

Well done, Sam.

That's a great example of pseudocode.

True or false? Pseudocode should always be written without breaking an algorithm down into smaller chunks.

Pause the video whilst you have a think.

This is false.

In most cases, it's sensible to break down algorithms into smaller, more manageable steps.

Pseudocode is an effective way to represent algorithms because A, only a basic knowledge of programming is needed to read, write and understand the logic.

B, it can be directly executed by a computer after being written, or C, it's exactly the same as Python programming language.

Well done, the correct answer is A.

Pseudocode is an effective way to represent algorithms, because only a basic knowledge of programming is needed to read, write, and understand the logic.

Okay, we are moving on to the next task of today's lesson, task B.

You're doing a great job so far, so well done.

Look at the written description of a dice game algorithm below.

Part one, generate a random number between one and six to simulate a dice roll.

Two, simulate a second dice roll with a random number between one and six.

Three, compare the two dice values.

Four, if the values are the same, tell the user they rolled a double.

Five, otherwise, tell the user they did not roll a double.

Use pseudocode to represent the algorithm.

Pause the video here whilst you complete the activity.

How did you get on? Did you manage to write some pseudocode? Well done.

Let's break this down into some steps.

So we first define the variables for the two dice rolls and generate a random integer value between one and six for each dice.

So we've got die_1 is equal to RANDOM_INT between one and six, and then we've got the same for die two, but it's just got a different variable name.

The next step is to create a procedure called check dice, and add the variables die one and die two as parameters.

We then use selection statements to check if the dice values match and print a suitable message to the player.

So on line five we have ID die_1 is double equals, the comparison operator, die_two, on line six, if that's the case, we are going to PRINT, "You rolled a double," and then on line seven we have the ESLE statement, with on line eight, the PRINT statement, "No double this time." And then at the end, we're going to add an end procedure marker to show the end of the procedure code block.

Don't worry if your pseudocode looks different to mine.

Remember, there is no standard convention for pseudocode and your GCSE exam board may want you to write it slightly differently.

Okay, we've come to the end of today's lesson and you've done a fantastic job, so well done.

Let's summarise what we have learned together.

The word pseudocode literally means pretend code.

Algorithms can be represented in pseudocode.

Only a basic knowledge of programming is needed to read, write and understand pseudocode.

Pseudocode must be translated into a real programming language, such as Python, for it to be executed by a computer.

I hope you've enjoyed today's lesson and I'll see you again soon.

Bye.