video

Lesson video

In progress...

Loading...

Hello, I'm Ben, your computing teacher for this lesson.

Now, this is our last lesson in our unit, which is Programming for Subroutines.

So what we're going to do in this lesson is put together all those skills that you've developed over the past five or six lessons and to make and create a programme of your own, okay.

We're also going to discuss a little bit about testing, and how we can test your projects at different stages of development, okay.

So all you'll need for this lesson is a computer and a web browser.

You'll also need access to you about Repl.

it account.

As always, please do ask your parents or carer before loging into that, sorry.

And if you can clear away any distractions that you might have, turn your mobile phone off, and if you've got a nice quiet place to work, that would also be great, okay.

So when you're ready, let's get started.

Okay, as mentioned in this lesson, you will be able to describe what is known as iterative testing.

You're also going to describe the types of testing that we can do.

Such as erroneous, boundary and normal testing.

And then finally, you going to put together all their skills and design and create a programme, okay.

So let's start off by talking about testing then.

Now, we mentioned this word iterative testing.

Now iterative testing is where you test your programme, make sure it works throughout it's creation.

So more kind of traditional testing, you might consider it to be, once you've made the programme, you test it at the end.

Well, iterative testing is making sure that you tested during development.

So once you make one little subsection, maybe a subroutine, you then test that subroutine to make sure it works before moving on.

So by running your code and testing often, you will find that errors are much easier to detect and correct.

Now, final testing.

This is a testing that happens once the completed programme is finished.

Now, during iterative testing, you might test the individual blocks of codes or subroutines as I mentioned, whereas final testing happens when all of those elements has been put together into one programme.

Now, when we do the final testing, there were three different types of data that we can enter into our programmes to test our data.

And they are erroneous, boundary, and normal testing, okay.

So let's go through each one of those in turn, and just explore exactly what's meant by those terms. So erroneous data is a good word that is not erroneous, okay.

Now, this is a type of data that should not be accepted by the programme, because by doing so, it would cause error.

So the one thing to remember about erroneous, is you're deliberately trying to, not necessarily break your programme, but put data in that, you know, is invalid.

It wouldn't be data that you want to be accepted by the computer.

Now, we have learned about things such as error handling, where we do the try and accept blocks.

So it doesn't necessarily cause error, because you might just catch that problem and handle it in a certain way.

But it certainly by using data that we don't expect to be accepted, okay.

Now, an example of that might be entering in a string where you know that you want an integer, okay.

Now normal data, this is data we do expect to be accepted.

Just normal day-to-day data that you know, we asked for an integer, so we're putting in an integer just to make sure it works as expected, okay.

That might be just to make sure the data is accepted, or maybe just to make sure the calculations work out correctly what you've done, okay.

Now, an example might be that, for example, when a user is prompted to enter their name, and then they should be able to just enter their name.

And you can see the code, that print, please enter your name, name equals input.

If I were to enter in Ben, that would just be normal data, okay.

That'll be a normal test.

And if it accepted that, and maybe the next part of the programme might say hello, and then the name saves it hello Ben.

Then I know it's worked, okay.

Now the final type of data is called boundary testing.

Now these are values that are the limits of validity.

And they should check that values at the boundary are valid, okay.

They should also check that values just outside the boundary are not accepted or handled when required, okay.

So an example of that.

If we look at this programme on the right-hand side here, you can see, it says number equals int input.

So expected number there.

But what we're doing in the boundary test is testing this while loop.

So the while loop will execute while the number is greater than zero, and the number is less than four.

So boundary test.

So this should accept data between one, two and three, okay.

So our boundary tests are the values one and the values three.

Because one is the lower end of the minimum value that we expect to be accepted, and three is the maximum value we expect to be expected, okay.

So that will be a boundary test.

Now we might also want to test on the other side of that boundary.

So once a minimum value that we expect to be accepted.

So what do we expect to happen when zero is entered.

Well, zero is still a boundary 'cause it's just on the other side of the boundary, but we don't expect it to be accepted, okay.

So we might want to test it on that condition too.

And the same as could be set at the other end of the boundary.

So the other end of the boundary, the maximum value of three.

So some simple tasks would be to also task with number four to make sure it doesn't accept that value.

That's just over that boundary line as such.

Now, in order to thoroughly check that our programme is working correctly, a test table is produced, okay.

Now the tests should include data from all three types where applicable.

'Cause it may will be that you can't have the boundary, okay.

It may will be that you're testing a name input, and that's all it is.

It's just accepts a string, okay.

And if it just accept a string and you've not put any other types of validation, there's no minimum or maximum value, then you might not be able to test it with any, you know, boundary data, okay.

Now here's an example of a test table.

And we can use it to test the while loop from the earlier example, okay.

Now we talked about that while loop.

So an example would be, we might, you can see our boundary test there, loop one and zero.

So the first one line one, it says test number one, test description.

So a very, very short description here saying boundary task for a while loop.

That's all we need.

Now input, that if there is an input, okay.

But if there is an input, we state what the inputs going to be.

So we're going to test it with the value one, okay.

And then what we do is we write down before we do the test, we write down what we expect the outcome to be not really important because if we just test it and we haven't really thought about the expected outcome, it can be a bit confusing maybe, whether the actual output is what you wanted happen or not.

So it's really clear and really important side to draw your line in the sand beforehand.

This is what we expect to happen.

So we type in what we do expect the output to say you are in range, okay.

Now we do the other one, boundary tests for a while loop, of line two sorry.

If we put input requires zero, okay, what do we expect the output to be? Well, if this was all my programme, I'd expect maybe nothing to happen Because it would ask me for zero and then nothing else happens.

It wouldn't say you're in range and it wouldn't ask me to enter a number, okay.

So at the end of it will be just put that, okay.

And you can see a normal test and you can also see an erroneous test.

So an erroneous test is aligned for that.

It says input quite hello, and then it should say, you should enter a whole number, right.

So let's have a look at what would actually happen, okay.

So I wanted to say, so in line four, you should enter a whole number.

So that's how it look, see what happens.

So when I tested it, I'm going to ask you to do number one.

It said that you were in range.

That's perfect.

So that did work as expected.

So actual expected output was you are in range and actual output was, you are in range.

So we don't need to do it.

The more than that, we're happy with that.

So it says if the task was unsuccessful, how was it successful? We can just put it in there because it was unsuccessful.

Perfect, let's go to the next one then.

Next one says no output.

So although it didn't enter the while loop, I would still count that as a successful test because we didn't want it to enter into the while loop.

So that's okay.

We're happy with that.

So nothing needs to be fixed.

The next one, normal task.

And we put in two, which should say you are a range and it does.

So we find that.

And the last one I wanted to put in erroneous tasks where I've typed in hello, and it should say you should enter a whole number.

So let's see what happened there.

Unfortunately, that didn't work, okay.

I thought it should say you should enter the whole number, okay.

But actually what did happen was there was a value error, okay.

So here, I'm going to write about what I need to do to fix that.

So once I fix that, what I did was I added a function to handle the value error, okay.

Or you might have had it in like a try and accept or something like that, okay.

Let's just give me a brief outline to what happened.

And it was always worth testing again.

If something failed the first time, then put the implementation and to fix it, but then test it again just to make sure, okay.

So that is testing, right.

What I'd like you to do now is put this into practise.

So we've gone through an example there, okay.

So I'd like to head over to task one on your worksheet, where there's a block of code for you to look up and I'd like you to develop a task plan before running it.

So you'd develop a task plan and then copy the page or paste the code into interval clips, okay.

Run the code and test it under each one of your conditions to see whether or not it did as you expected it to, okay.

So pause this now, and then un-pause it when you've done that.

Okay, so how do you get on with that? So hopefully now you're feeling really comfortable with being able to produce a task plan.

So now we're at a stage where over the past six lessons now you've developed a whole range of strategies to be able to produce a really good programme.

So you've got my challenge to you is to actually go ahead and do that.

So I'm going to give you a scenario and then we're going to work through what exactly the requirements of this task are, all right.

So let me read it to you.

So it says Copington Adventure Theme Park has just purchased an automated ticket a ticketing system, and we'd like you to programme the interface for customers to use.

So the ticketing system should ask the customers various questions about their visit requirements before providing a total charge, asking for payments and issuing a ticket, okay.

So quite a few things in that, but your worksheet does get expand on this in a little bit more detail.

This is just an overview.

So in a moment, you'll be going to be able to go to Task 2 on your worksheet, but I'd like to take a few moments when you go to Task 2 to really read the requirements carefully.

So I've just given you an overview, but on Task 2 on your worksheet, there's a bit more information that I'd like to just spend a little bit of time reading and just digesting all the information that's there, okay.

So in this task, I would like you to design the programme using pseudocode or a flow chart.

Now, if you remember back to a previous lesson, we looked at structure charts.

Now the structure chart has been made for you.

So what I need you to do is use our structure chart to help you create that a pseudocode of flow charts, okay.

Then you're going to create a programme.

Then you're going to test it using a test table.

So the design itself, your first task will be to create the design for the main programme and each job routine, okay.

And you can use a pseudocode or flow chart, whichever one you feel most comfortable with, okay.

Now I can mention this structure chart has been made for you and the structure chart outlines, what kind of sub routines we need and what the function there is.

So that will be, yeah, well, the function names are going to be, and what values they should return.

So it will really help you create your pseudocode, okay.

So definitely use that.

Then once you've done that pseudocode, I would like you to then create your programme.

So go ahead and open it, create a new Python file.

I'd like to write your code to solve this problem, okay.

But definitely use your design work to help you, because once you've gone through that process to look at the structure charts and designing code, using pseudocode.

Actually the code creation process should be fairly straight forward 'cause you've done all the groundwork already, okay.

Now, remember we said about this iterative testing, make sure that you test often, don't write like 20 lines of code without hitting that run button, okay.

Maybe write a sub routine, then run and test.

They put it under different conditions, okay.

And then move on, okay.

Now, once you've written all your sub routines and you've got to complete the programme, then do the the following testing, okay.

Do that under the development testing.

So create a task plan, okay.

And then make sure where suitable you put in some erroneous, boundary and normal test, okay.

And then test it under those conditions and record your findings, okay.

And then that is the end of your project.

Now I would expect this whole process to take your minimum of about two to three hours working on it, okay.

And that's a minimum, so don't worry if you spent two hours on it and you know, you still got fairway to go, okay.

What I definitely want you to do is I'd like to take your time on it because, you know, this isn't about rushing anything.

This is about making sure you can feel really comfortable and happy with the project that you've made.

Don't be afraid to look back over the previous lessons, work that we've done, okay.

That will really help your, of your previous lessons or present previous Python files that you got saved on your uplift.

Use those to help as well, okay.

And definitely have fun with it.

Now, I would like to make a note of what time we're up to on this video, because I would like you to maybe pause this video now, or maybe even turn this video off, go ahead and really concentrate on the project.

And then when you finished it, okay.

Or you don't feel that you can carry on anymore than unpause the video 'Cause the next thing I'm going to do now is go through the solution, okay.

But I don't want you to never heard, and see the solution before you've had to go at yourself, okay.

Do have a go yourself, do try it.

But like I said, if you've really stuck, just watch a video and we'll go through some of the, the projects, okay.

So good luck have fun, okay.

So I'd like to pause the video now, go to Task 2 where all the instructions are there and have fun with it.

And I will see you soon.

Okay, so this is the part where I'm going to go through the solution.

I'm not going to spend time writing all the code in front of here, but I'm going to talk you through each one of the sub routines and how that's meant to work and also how the programme is meant to flow once I've created the sub routines.

So you might be watching this just for confirmation that you've done it and it's so well done, but you might also be watching it because you're stuck at a certain points.

So if that's the case, what I'd recommend that you do is you follow the video through to get to the bit that you felt stuck up, then maybe pause after I finished talking and then don't continue with the rest.

So if that maybe helps you get unstuck and move on, then just pause the video, minimise it, and then continue working through the projects and unpause, if you get stuck again, all right.

So my first part of call from doing all of this was to use my structured diagram.

So let's have a look at that photo.

So I'm going to do a swapping between the structure diagram on my coat, right.

So you'll notice that if we start on the left-hand side here, I've got entrance tickets, right? So my identify with entrance, it took three parameters and the tops and the return was total cost, right? So let's have a look at how I've done this.

Now, ignore this for the time being 'cause I'd rather than it does something I needed over and over again.

And I used over and over again, we use on a previous programme.

So hopefully work that I have even just copied and pasted the previous code that you've done Don't ever reinvent the will.

If you're using a function that you think, Oh, I've done this before I made that function for that exact function, then go and use that again, right.

Go and copy and paste them, put it in.

, anyway, right.

So the first one I go back to entrance its said it needed the three parameters.

So I put them in.

So I'll put def entrance.

I put my three parameters in.

Now to work this out, you see I've got a running total cost.

So my total cost, first of all, is the child total time by 12, 'cause that's how much your child took is.

And then my next cost I'm overwriting with total costs equals total costs.

So the value that says worked out by the child total costs plus the adult times 20, okay.

'Cause that's the other price and I've done the same for senior.

Or you might have done that slightly differently.

You might just work out child total stored in available called child total or something, okay.

Or just child and then had one for adults and senior.

And then your total cost has been 300 together, okay.

That's the way I've done it.

Not necessarily only way to do it.

There's what I'm trying to say, okay.

Then I'm turning the total cost.

So that's that function done, okay.

Next function, okay.

It says the wristband, the wristband was identifier.

I only need wristband total in there and I'm going to return total cost.

So if I look at this one, that's here, you'll notice I've got, def wristband.

I'm taking a one parameter.

And the total cost is the number of wristband required, which has been passed in here typed by 20.

And then it could to return the total cost of the wristband.

The next one was surname.

So this one didn't take any parameters and nothing's being passed into it, okay.

But I'm going to return the surname.

So this is just handling the bit where we're asking for the surname.

So def lead surname, print, please enter your surname.

I've got an input here.

It's going to store under the variable surname.

And then it's going to return it back outside the functions.

That's that one done.

The next one was a car parking.

So the identify was parking again, not taking any parameters.

And there is a return, return is required whether or not they require parking.

So my parking, as I've got some nice print lines here same parking is completely free.

I come to the Adventure Theme Park, another print line.

You must display a parking pass in your vehicle.

Do you require parking? Yes or no.

And then I've got this thing called required.

And what I've done is I put inputs.

That's going to accept what they answered, yes or no.

And then I put the upper to make sure that wherever they put, if they put it in uppercase or they put it in lowercase matter, which one they do is going to make sure that input is converted into upper case, okay.

So it's going to say while required is not equal to yes or not equal to no.

So a Y or N is going to say, it's going to pick up that kind of error there just in case they put a number or they put the word, yes, okay.

It's going to then ask them to do it again.

So it's going to say, you must enter Y or N, and ask them again.

And once they've done that, it breaks outside the loop.

And then we go back to this return steam.

So it's just going to return what they entered, whether or not they entered at Y or N, okay.

So the next one then is we're getting there.

So it's collect money.

So that identifies collect.

We're taking the prompt total cost and we're not returning anything, okay.

So that was not a function anymore, okay.

It is a, what's it called again? It's not function, can you remember? So procedure, well done, okay.

So if we go to collect here, so def collect total costs, okay.

So all this is going to do is going to take in the total cost, but it's going to print out to them what the total cost is.

But also it's going to then do their, with the money side of things.

So it's going to say, this machine will only accept 10 and 20 pound notes and that was on your requirements.

So it says amount paid equals this.

That's our starting amount because they don't pay anything yet.

So that's going to be set as zero.

And it's going to say, while total the cost is greater than the amount paid.

It goes to essentially, it's going to keep us in them for more money until they paid their amount, right.

So we can say, where you enter 10 or 20, okay.

Now, so is going to ask them to enter a value.

Now notice at this point, enter a valid integer, okay.

Now it's going to make sure that they enter this integer.

It's going to call my function above, which is going to make sure that they enter in a whole number, right, okay.

So it's going to say if the amount once has validated that number, if the amount is 10, okay.

Then it's going to say amount paid equals money paid plus 10.

So it's going to increment the amount paid.

Otherwise, if there's 20, is contentment incremented by 20.

Otherwise it's going to say, hang on, the machine only accepts 10 and 20 pounds.

Don't try and enter any of the value, right.

Now, then what's going to happen is once we get to the total cost.

And once we put more money than the total cost is going to exit outside this while loop, okay.

And then we've got an if statement is going to tell you how much you paid and then we've got lift them to you're saying, if they overpaid, they were paid, the amount then what's going to do is give them some change, okay.

And print out what their change was, okay.

Next, we've got two more left now.

So it was issue ticket and car pass.

So issue tickets.

So they identify it as issue ticket to be along these prompters, but didn't return anything.

So this is only the printing of the tickets.

So here, what we've got is all the prompters have been worked out so far.

That's going to give a little print message.

It's going to put today's date in there.

This is how I've done that.

I'll put the date they got today.

Now, if I was going to do that right at the top, you'll notice I put from date time, import date, okay.

To do that.

So it put today's date.

It says tickets valid on.

So it's going to put in that date, which is that.

Lead Booker, it's going to use a surname that's been passed into it, okay.

It's going to then use adult total, child total, senior total and risk total, all right.

Then so that's just going to print out the parts for them.

Then the car pass, it's going to print out of the car pass.

So the identifies car pass, and it's just going to print it out.

So basically if they, you saw earlier, if they did require a ticket, simply I put my flat lasky code here, which is going to print out car pass.

So those are all my sub routines, okay.

All completed.

So the next bit was to run that the programme in the right sequence, okay.

So the first part was to say, welcome to Copington Adventure Theme Park.

Tell them what the prices were.

And then the first thing that's going to do is how many tickets do you require? Then I'm going to call well, adult total that.

So I'm going to call my valid integer to make sure that works, but store the answer on the available called adult total.

Let's going to do the same for children's tickets, going to make sure they entered a valid integer and store under that variable, their child total.

And then I've got senior citizen tickets, exactly the same, right.

Now, once I got that, my total cost.

To actually work out the total cost, I call my entrance sub-routine and pass into it.

My child costs, my adult total and my senior total there, okay.

That was going to run the function.

That's obviously going to have a turn something back, my entrance sub-routine return something back, okay.

And that's going to be stored on the total cost.

So then I'm going to say how many visitors required wristbands, okay.

So they've got a wristband total.

So I'm going to make sure it's a valid interject.

And then I'm also going to increment the total cost.

So my total cost has already been worked out here.

I ain't going to add to it.

So I'm going to take my total cost plus my wristband function and pass into it.

How many wristbands were required? Then we got a lead surname here, okay.

So it's going to store their surname.

It's going to say whether or not they required parking, okay.

When I collect function there, when I issue a ticket function there, and if the car parking was yes, then print the car pass, okay.

So that's all of my finished programme.

So next thing was left, you testing.

I hopefully you were doing some adequate testing, but, and also you need to go through and do a full test plan to make sure it works.

Now I'm not going to do a full task plan test on the various data.

I'm only going to test it on the normal data to make sure it works, okay.

And more to prove to you that this code works.

So, first of all, it says, how many adult tickets do you require? Well, I require five tickets, okay.

So the whole family, how many child tickets? Oh, now come wrong.

Let me start this again.

'Cause I don't want five out of them.

Two adult tickets.

So how many adult tickets to you require? Two, how many children's tickets do you require? Three, is about five in total.

Not taking any senior citizens, okay.

Now how many visitors require wristbands? So three wristbands.

And your surname? My surname is Garside, okay.

And park is completely free, would you like parking? Yes, I do want parking, so yes.

And your wife? Yes.

And total cost is 136 pounds.

136 pounds is expensive, that's Theme park, okay.

Now, so I've got to make sure I've got lots of notes available for me to afford this, okay.

So I might need to go and speak to the bank manager just for a loan.

But anyway, I'm going to pretend the bank manager has given me a loan, 120 pounds.

So instead of entering 20, 40, okay.

This is going to be a total paid, another 20 pounds, 60 pounds, 80 pounds, 100 pounds, okay, 120.

Now, let's work out what should happen here? If I point 20, that's going to take my total 140.

Now total price was 136.

So that should give me how much change? Okay, that's right.

It's four pounds change.

Let's see if that works.

So get the answer, last time we read this.

So it says your total is 140, your change is four pounds.

That works, okay.

And then you can see it has given me my ticket that and my parking place,a parking pass.

Thank you for your purchase.

Have a great day, but I'll tell you if 136 pounds.

I really hope it is a great day, okay.

Anyway, that was all the code as such.

So you haven't yet completed the task plan, please go ahead and complete that task plan and then you will return to the video.

Okay, so good luck.

Okay, so that's all for this lesson and that is all for this unit.

Now you've come in for a long way in this unit and you really should just take a break and give yourself a big pat on the back, particularly if you are able to complete that last project.

Okay, so big, massive, well done.

Okay, and you're well on your way to becoming a really good programmer, okay.

Now I would absolutely love to see your Theme Park projects if you completed them, okay.

Maybe even taking them a step further and add more functionality.

And if you've done that, please share it with us.

I would absolutely love to say it's okay.

So if you'd like to share your work, please do, and please ask your parents or carer to share your work on Instagram, Facebook, or Twitter tagging @OakNational and using the #LearnwithOak, okay.

So I really hope you've enjoyed that and please do continue learning and developing your code in the next unit that we've got, okay.

That's all for me.

So I'll see you soon, bye.