Loading...
Hello.
My name is Mr. Hogan.
I'm excited to be learning with you today.
We are going to have such a great time learning all about programming iteration.
I will be supporting you with our learning during these lessons.
I'm so pleased that you've decided to learn about designing robust programmes.
We are going to do brilliantly.
Excellent.
Brilliant, we're gonna look at the outcome now of the lesson.
So the outcome is I can use a project brief to plan a programme using flowcharts.
I'm so excited to look at this project brief and to start planning it.
It's going to be great.
We have three keywords to this lesson.
So these keywords we'll use throughout the lesson, and you can always come back to them if you want to, be reminded of what they mean.
So decomposition, so this is breaking down a problem into smaller parts to make the task more manageable.
We've got pre-condition loops.
This is a loop that checks its condition at the start before any code inside the loop is run.
We have post-condition loop.
This is a loop that runs its first code, then checks the condition at the end to decide if it should be repeated.
The lesson is split into two.
So the first part is investigate a project brief, and the second part is design a programme using a flowchart.
This is gonna be a great lesson.
I hope you're looking forward to it.
Let's move on to the first part then, investigate a project brief.
So this is the brief.
You have been asked to develop a game using Python.
FizzBuzz Challenge Station is a new game terminal being trialled at Hilltop Holiday Park.
The game is designed to test players' logic and pattern recognition skills.
So this is like going into the holiday park, like a challenge station, like a game station where it's being trialled and you need to come up and develop a game using Python called FizzBuzz Challenge.
The system must prompt the player for the number of games they would like to play.
For each game, the player sets a range of numbers, for example, from 1 to 20.
The system then plays the game automatically using FizzBuzz rules and displays the result.
So the FizzBuzz rules for numbers in the chosen range, okay, so this is what the FizzBuzz rules are.
So print Fizz if the number is divisible by three.
Print Buzz if the number is divisible by five.
Print FizzBuzz if the number is divisible by both.
Otherwise, print the number.
So you may want to just realise that these are the rules.
And you may want to rewind the video at any time to go over the brief again or pause the video.
The project brief specifies that the programme should do the following: display a welcome message, ask how many games the player wants to play.
For each game, ask the start and the end of the number range.
Validate the input, so numbers only in a sensible range.
Play FizzBuzz using a for loop.
After each game, ask if the player wants to continue, and then display a goodbye message.
Use while loops and nested loops where appropriate.
Use randomization to add variation.
Use try or except blocks to catch errors like ValueErrors and TypeErrors.
Ensure that code is robust and does not crash due to user input.
So hopefully you're starting to think and investigate this project brief and think about, "Oh, we may have done parts of this at some point in our lessons." Also to help you a bit, we've got an output from the programme or something similar that it may look like.
So we've got that welcome message, how many games they want to play, so two is entered.
Then it starts off with game one.
Enter the start of the number range, enter the end of the number range, and then it gives the results.
Take your time to look at the output.
So this is the output continued.
So you can see that the results are all there.
And again, it's prompting if you want to play another game.
And then the results.
And then a goodbye message saying, "Thank you for playing the FizzBuzz Challenge Station!" So that's the end of the output.
Remember, you can go backwards in the video to go over things if you want to go back and look at what the brief is or what the output would look like.
Let's have a quick check.
Which of the following is not a requirement of the FizzBuzz Challenge Station? Is it A, after each game ask if the player wants to continue? Is it B, keep the score as the game progresses? Or is it C, ask how many games the player wants to play? Remember, you can pause and rewind the video anytime and take some time to think for you about your answer.
Okay, let's have a look at the answer.
It is B, keep the score as the game progresses.
Yeah, that is not a requirement of the FizzBuzz Challenge Station, but A and C are.
Well done if you got that right.
So using a structured approach means breaking down a problem into smaller parts to make it easier to solve.
This process is called decomposition.
A diagram can be created to decide the different parts of the programme, so something similar to this.
So let's have a quick check about that.
Decomposition makes programmes more complex to solve.
Is this true or false? Remember, you can pause and rewind the video any time and take your time to think about the answer.
So the answer is false.
Why? You know, well, decomposition simplifies problem solving by breaking down a large problem into smaller, more manageable parts.
Once you've broken down the problem, you need to think about what each part needs to do.
So this first part, the system will need to display a welcome message to the user.
Time for a practise.
So one, plan out the remaining parts for the FizzBuzz Challenge Station.
So what other things can a FizzBuzz Challenge Station be broken down into? Remember, it'd be really useful now to rewind the video and to double check that you've understood the project brief and the output will help you as well.
So take your time, think about how you're gonna break down the problem, the brief, and you can pause and rewind the video anytime.
Good luck.
So this is a sample solution.
You may have divided the problem into different parts, okay? But you could divide it like this.
So we've got it broken down into the displaying a welcome message, you were given.
And then ask how many games.
Ask for a start and end number.
Go through the range, and also handle any errors.
So well done if you've broken down a problem, even if it's slightly different.
Well done.
Two, plan out the remaining parts of the FizzBuzz Challenge Station.
So we've done that for the first one where we've got display a welcome message.
The system will need to display a welcome message to the user.
And also you may need to add more parts to your plan and give it more detail.
So good luck with this.
Well done.
You may pause or rewind the video at any time.
So possible answers, we've got ask how many games.
So the details to this could be ask the user how many times they want to play, and ensure that they enter a valid whole number.
Then we've got ask for a start and end number.
So this will get the range for the FizzBuzz loop, validate input and check that start is less than the end.
So we've got some validation in there.
And then we've got go through the range, so use a for loop to go from start to end.
Print number, Fizz, Buzz or FizzBuzz.
And then we've got handle errors.
So this is where we're gonna use try and except blocks to catch errors.
So hopefully you've got something similar to this, but now you may be slightly different to what's displayed here, but well done for getting this far.
Amazing.
Well done.
That's the first part of the lesson complete.
Now we're going to move on to the second part, design a programme using a flowchart.
A flowchart is a diagram used to illustrate the steps of an algorithm.
Flowcharts are made up of symbols, each containing a single step from the programme.
The shape of the symbol represents the type of step that the symbol contains.
And arrows are used to show the flow of execution.
When investigating the requirements of a system, it is useful to plan the programme, flow of the programme using a flowchart.
The flowchart symbols include these.
So you've got a terminal, you've got a process, and then you've got a flow line and an input or output symbol.
So these are all used when designing a flowchart.
So diamonds are used for decisions when using flowcharts.
And we normally have two flow arrows coming off the diamond to show if the condition is true, it's yes, or if it's false, it's no.
Which flowchart symbol is used to represent an input or output? Is it A, B or C? Remember, you can pause the programme at any time and take some time to think about the answer.
The answer is B.
So an input or output is represented by this symbol.
Laura has created a decision symbol for the FizzBuzz Challenge Station system.
So is start less than end? So if it's true, it'll follow the yes flow arrow.
If it's no, if it's false, it'll follow the no flow arrow.
All loops make use of selection conditions when iterating.
Some loops check their condition at the start of the loop.
These are known as pre-condition loops.
Other loops check a condition at the end.
These are known as post-condition loops.
Pre-condition loops check a condition before running any of the statements inside the loop.
This means that in your flowchart, you will place a decision symbol first followed by the statements inside the loop.
After all the statements inside the loop have run, the flow of the code returns to the decision symbol and the condition is checked again.
If the loop terminates as a result of this check, the flow of execution branches off from the decision symbol and the rest of the programme is executed.
It's a lot to take in so you may want to pause the video and reread this information, or even rewind it a couple of slides and play it again.
So this is a start to a flowchart where we've got starts and then count equals zero.
And then we're saying a cision symbol happening here where we've got count is greater than six.
If it is greater than six, it's true.
So therefore we stop and follow the yes flow.
If it's no, we display count, and then we add one to count, and then it flows back to the condition again.
So this would loop around until it reaches greater than six where it will stop.
So for post-condition loops in a flowchart, you'll first place the statements that are inside the loop first, followed by the decision symbol.
The flowchart shows that all the statements in the loop will be executed before the condition is checked.
Once the decision simple is reached, the condition is checked.
If the loop continues, the flow of code returns the first statement in the loop.
If the loop terminates, the flow branches off from the decision symbol, and the rest of the programme is executed.
So let's have a look at this in an example.
So we've got start and then answer equals green.
Then display, so that's an output.
What colour is grass? That's a question.
And then the user enters the guess.
If the answer is the same as guess, then we follow the yes flow and we display correct and stop.
If it's false, so if it's not, we go back to enter guess.
And that will loop until it is correct, and then it will follow the yes flow.
So it's time for practise.
One, create a flowchart to represent the whole FizzBuzz Challenge Station system using the project brief to help you.
Remember that you split the project into smaller tasks in task A.
So you can create smaller flowcharts to represent each task.
So you may want to pause the video, rewind it, maybe make some notes.
But hopefully you'll have to take some time to create this flowchart for the whole FizzBuzz Challenge Station.
Good luck.
So let's have a look at the answer.
This is over a few slides.
So we obviously start, and then we display the welcome message to the user.
We then input the number of games.
Then we go to a decision box where we are checking the validation, we're checking the validity and using validation.
So is it a valid input? If it's not, we go back to input the number of games.
If it is valid and it's true, it's yes and we go on to the next part.
So then we ask for a start number, and again, we have a decision box saying, is it valid? If it's not valid, we loop round and we go to ask for a start number.
If it is valid, then it's yes, we move on.
So very similar to the last slide where we have ask for the start number, we're asking for a finish number and then say asking if it's valid or not in the decision box.
Then we are asking for is the end number less than the start number? If it is, stop.
If it's not, we calculate the result, display the result.
And then if, then we add the start number, we add one to the start number and we loop around.
So it takes some time to look at that.
Great.
So well done if you've got something similar or very similar to this, or you may want to go back and update your answer, take into consideration what you've just seen.
That's brilliant.
It's the end of the lesson.
So in summary, decomposition means breaking down a problem into smaller parts to make the task more manageable.
A flowchart is a diagram that visually shows the steps of a programme.
Pre-condition loops check their condition at the start before running the code.
Post-condition loops run the code first, then check the condition at the end.
Well done.
I hope you enjoyed the lesson.
I certainly did.
Brilliant.