Loading...
Hi, there.
I'm Rebecca, your computing teacher for this programming part two unit.
Now for this lesson, you're going to need that Repli account that you should have already set up with your parent, or carer's permission.
You're also going to need a pen and paper, so that you can answer any of the questions that I give you in this lesson, and to perhaps make notes too.
You're also going to need to make sure that you remove as many distractions as possible so that you can really focus in this lesson.
Once you've got all of that ready, we can begin.
In this lesson, you will evaluate arithmetic expressions, using rules of operator precedence, or BIDMAS.
You might've heard it as that.
Write and use expressions that use arithmetic operators, and assign expression to variables.
Let's see what you can remember from your math lessons then about arithmetic expressions.
So here you've got a variable number, and an expression is being assigned to that variable.
Now what I want to know, what does that expression evaluate to So what would be the answer, if you were trying to do this in a maths lesson.
What value will be held by the variable number, do you think? Pause the video, while you have a think.
Let's take a look at the answer then.
So the answer is 18.
And you possibly didn't get to 18, and that might be because you were doing the operations in the incorrect order.
and he might not have remembered how to use BIDMAS, which is what we're going to be learning about at the beginning of this lesson.
So arithmetic expressions are evaluated in order of operator precedence.
You can use BIDMAS to help remind you of the correct order.
It is important to note the add and subtract for are interchangeable, and should be evaluated from left to right.
And that's just a reminder of what that.
What the acronym BIDMAS actually means.
So brackets, indices, division, multiplication, addition, and subtract.
So, in your math lessons, you might have seen BIDMAS represented in a triangle like this.
So you've got the brackets at the top, then indices and then division and multiplication, and then finally, you've got addition and subtract.
So let's take a look at our example then.
10 takeaway 2 plus 2 times 5.
So if we look at our BIDMAS acronym, there aren't any brackets in the sizzle division in these, so we go straight to M.
There are no brackets, so we go straight to M.
So we do two times five, which is 10.
And then we have 10 takeaway 2, plus 10.
So we're on our bottom line now of our triangle.
So add and subtract should be read from left to right, if the subtract appears first, then this should be carried first.
And in this situation, it does appear first, so 10 takeaway 2 is eight, and then we're just left with 8, add 10.
So finally you're less with one operator, and perform this final calculation.
So 8 plus 10 is 18.
And there's our answer.
Here is a list of arithmetic operators that can be used in Python.
So you might not be familiar with all of them.
If you've used a spreadsheet before, you've probably seen the things like using a forward slash for division.
Now into division and modulo, a possibly unfamiliar terms to you.
Here is an example of how real division will output.
In real division, there is no remainder because the entire value is divided.
So if we do 14 divided by 3, and the answer's going to be 4.
6 reoccurring.
When you use integer division, it will discard the decimal part.
Integer division is the operation, that calculates how many whole times the divisor, 3, will fit in the dividend, 14.
And in this case, the answer is 4.
Modulo, is what is used to work out the remainder of the division.
Which in that case, was 2.
If you divide, 14 counters between 3 people, then there will be 4 counters each with 2 remaining.
Like you can see here on the diagram.
The MOD, doesn't simply store the value that was discarded from integer division, it stores the whole number that was remaining.
So it's not storing the six, six, six, six, six reoccurring, It's storing the whole value that was remaining.
So if you look at that code there on line one, if we're using integer division 14 divided by 3 is 4, and then 14 MOD 3 is 2.
So with 4 each with two leftover.
You would use modulo, when you needed to find out the remaining whole value.
This will be helpful in many cases.
An example might be when you wish to find out if a value is odd or even.
If the value evaluate as a 1, then it is odd.
Just like it is here.
If the value evaluates as zero, then it's even because there are no remainders.
So into division and modulo.
Let's see what you've remembered from that.
So what value will be held by the variable number in this situation? So we've got there the percentage symbol, so that means that we know are using modulo in this situation.
It's not into division, it's working out that whole number that is remaining.
So see if you can do a calculation there in your head 25 modulo 4.
Pause the video while you have think.
Right, let's have a look at the answer there.
So the answer one, what did he get that right? So there'll be one whole number remaining after you've done this.
You do 25, divided by 4.
So 4, 8, 12, 16, 20, 24.
So you can fit it neatly six times, but then there's one remaining.
And that's why that one is remaining there.
Then you've got to 10 divided by 3.
Now this is just a single forward slash so this time it's real division, not integer division.
So hopefully that will help you figure out what the answer might be here.
Pause the video while you have a think.
Let's take a look then.
So it was A, because we're doing real division, you're going to see that remainder there.
The reason to remainder, because it's actually worked out how much it would divided by that value.
So in this time, you've got three, and then you've got three reoccurring carry on me, cause it's a real number, it's using real division, so it's going to hold a real value at the end.
So a real value, is a decimal value.
Now, this time we've got the two forward slashes, which means integer division.
So we've got 13 divided by 3.
And then the answer is going to be a whole number this time.
See if you can look at those answers.
I think I've given you a bit too much of a clue there.
So if you can look at those answers and figure out what he might be.
Well, it does definitely wasn't B, you was it? Okay.
Let's see what the answer was.
So the answer was 4, because 13 divided by 3, is 4.
So if you were doing the 3, 6, 9, 12, you can only get three into to 12, because then you'd have one remaining.
So it'd be four with one remaining.
So the modulo value in that situation would be one, because it'd be one whole value remain.
So you're going to pause the video now, and you're going to take a look at your worksheet.
Now this is an activity that uses those key things.
So it's got into your division, real division and modulo in there, and you'll be able to practise using them.
So you're going to use this split my bill worksheet, to investigate a programme that has been designed to help friends split the bill at a restaurant.
So pause the video, while you have have a go at that.
Excellent.
So, we're going to go through the solutions now to see how far you might have got.
Now you might have struggled a little bit with that, and that's absolutely fine because you can follow along now with my demonstration, and you can see what those solutions might be.
So let's go and a look in our Repli accounts.
I'm going to run through them with you, the investigate and modify tasks, just so that.
To clarify some things, maybe you were struggling just to clarify what some of those answers might have been.
Now you should have already done the predict and run.
So you should have had a good look at that code.
Try to read it as best as you can, make a prediction about what's going to happen and how it's going to work.
And then you should have run it, and then typed in some values to see what was actually happening.
So, I'm hoping that you've already done that, and that bit wasn't too bad.
So I'm just going to run it myself.
It says, welcome to split my bill.
What is the total bills? So, I'm going to put a hundred pounds.
So how many people sharing full? What percentage tip would you like to leave? 10%.
And then it says, total bill including tip is 110.
Total cost per person, is 27 pounds 50.
So, from reading the programme, you could have made a bit of a prediction about it.
And then when you run it whole through that clarified things, maybe some things surprised you about the programme, and maybe they didn't, maybe you got it exactly right.
So, that's just a basic run of the code.
And then you had some investigation questions.
So that first question was, what is the first question that is asked by the programme? So I've already run it.
And the first question is, what is the total bill? The next one, what data type is being used for the bill total.
So if we go over to here, we can see bill total equals float.
So actually casting float there, because, input always returns a string.
So then, you need to cast it to a different data type, If you want to use it as a different data types.
So in this situation, it's float.
So you could have put float or you might have put real, cause they're just two words that we use for that.
Or you might put decimal number as well.
All those three things are valued answers there.
And then it says, why is this datatype needed for the bill total? Well, if you think about money and currency, then you do have decimal values when you're talking about money, so you're going to have to hold it as a decimal value.
Then step four was online five, what type is being used for the number of people? So, go to line five and we've got people, and this time, you can see that we've got their int.
Now int stands for integer, And an integer is a whole number.
That it says, why is this data type being used? Well, people, you can't have people in halves or is it decimal, you have to have them in whole numbers.
So that is why an integer would be used there.
Then you've got, lines seventies used to enter the tip, the percentage tip that the group would like to leave.
What is happening at line nine? So line seven, is where you input the tip percentage.
And then it says, what is happening at line nine? So let's look, who've got a variable that it's called percentage decimal.
And then it says, tip percentage, divided by a hundred.
So what's happening there, is it's doing a real division cause it's a single forward slash, and it's dividing that tip percentage that's been typed and it's dividing it by the hundred.
You've then got step seven.
What is calculated at line 10? So let's take a look.
We've got tip total is the name of the variables.
So that would give you a little bit of a clue there.
And it's doing bill total, times percentage decimal.
So it's actually working out how much tip we would need to leave.
That's what line 10 is doing.
And then step eight says, online 11, the variable bill total, so here we go.
Online 11, the variable bill total is reassigned with the expression bill total, plus tip total.
So that's, what's happening there.
Describe what is happening here.
So what it's doing, is it's taking that initial value for bill total that was entered here, and then he's adding it to the tip total that is just been worked out there online ten.
So, if it was 10 pounds for the tip, like it was in my situation, then that would be added to the bill total to create the, the grand total bill.
And then steps step nine says, what type of error occurs, when time syntax or logic when you enter hello for the first question.
So let's just see what happens.
So we've got here, Hello.
Now, what what's happening there, is it's trying to convert that hello text, to a float value by casting.
So this is actually causing a runtime error, because it's an error that is happening during runtime.
So, that is all of the investigation stage.
So if you weren't too sure about some of those hopefully I've clarified Durbin, and if not, if you just got them all right, when well done, you should have ticked them all right, as you're going along.
So then next, you had a modified tasks.
In that modify tasks says, lines 9 to 11, contained three separate arithmetic expressions that calculate the final total bill.
So let me just highlight those now.
So 9 to 11, and you can see there's three arithmetic expressions that are there.
And it says, use your knowledge of BIDMAS to write a single expression, that performs the same calculation.
So what I'm going to do, I'm going to leave those three things there, cause I'm going to need them to help me figure this out.
And I'm just going to put.
I now I want to have bill total, because that is the value that I'm trying to figure out.
So I'm going to have bill total as my variable, but I've got to figure out, well, what arithmetic expression do I need to assign to this variable, in order to make sure that I've worked at the new bill total, that includes the percentage tip as well, but I've done it all in one expression.
So I need to look at those three expressions that are already there to give me a clue.
And then I need to think about BIDMAS and how I actually structure that expression.
And you will have come up with different ways to do this.
So don't worry if it's different to mine, as long as it works, that's the key.
So, to work out the percentage for a tip, I know that I've got to work out the percentage decimal as a decimal.
So if they said 10%, if they've typed in 10 on the keyboard, I need to convert that to a decimal, by dividing it by a hundred.
So if they type 10, I want it divided by a hundred, so it becomes 0.
1.
And then that means, that when I'm multiply it by the bill total, it will give me the tip total.
Cause it all times 0.
1 by the bill total and it'll give me the answer.
So then I'm going to think, well, how has BIDMAS going to work in this situation to make sure that it's all done in the correct order? Cause I don't want to have the tip taken off the bill, for example, by accident, if I've got a minus or a plus in the wrong way, or brackets in the wrong way or something like that.
So, first thing, what old work do I have to do it in? So I'm going to put a bracket in, and I'm going to do the tip percentage divided by a hundred.
So tip percentage divided by a hundred, because I know I've absolutely got to work that out.
The next thing, is to work out the percentage.
So taking that bill total, so if I typed in a hundred, how am I going to work out the actual tip value now? So this is just working out the tip percentage that a be in the brackets, but now how do I work out the tip from the actual bill? So if I times this by bill total, then that will give me the actual tip value.
Then I've just got to add it back, to the original bill total, which was entered on line three.
Now, at this point, I could try putting just bill total, but I think for me to be on the safe side, what I'm going to do, just to make sure that this bit happens first, I am going to put brackets there as well, just to make sure that it happens first.
And I will have to test my programme, to make sure it works too.
So let's just have a look at it now, and it's just see what's happening.
So I've got the tip percentage, divided by a hundred, so that it works out that decimal number.
So if I'd put a hundred at 10, it would be 0.
1.
And then I do 0.
1 times a bill total.
So if it was a hundred, the bill total by times up by 0.
1, and it's going to give me 10, which would be the tip total.
Then, I want to add it to the original bill total, which was a hundred.
So I want to add a hundred to 10, so it should be 110.
So I think I've done it right, so I'm going to get rid of these, and I'm not going to delete them.
What I'm going to do is, I'm going to use the hashtag.
So think about when we learn about commenting, in a previous lesson on randomization, you learned a little bit about commenting, what you can do if you want to just test things, and you don't want to get rid of any code that you've done.
If you just stick a hashtag in front of it, then when it's compiled and run through the development environment to execute, it will ignore those three lines of code.
So I'm just going to do it like that, and I'm going to see what happens.
So I'm going to use the same value as it did before.
So what is the total? 100.
How many people? Four.
What is a tip percentage, ten.
And is doing exactly the same thing.
So total bill, including tape is 110, and total cost per person, 27 pound 50.
So I know, that my new arithmetic expression actually works.
So you might've got something similar to that, or just study slightly different way round, as long as it works, then it was correct.
Okay? So don't worry if you've done it slightly different to me.
Fantastic and well-done for getting all the way through this lesson.
I know it's probably been a little bit of a challenge for you, but hopefully my having my demonstration there at the end helped clarify some things for you if you were struggling.
And with programming, it's always best to try, try, try again, and try and use the help as much as you can.
So those worksheets that you're given, have lots of help and support on them.
It might seem like a lot of information that you're being given, but there is all there to help you.
And there's always my demonstration afterwards to just clarify some of those things too.
Now, if you'd like to please ask your parent or carer to share your work on Instagram, Facebook, or Twitter tagging @OakNational and hashtag learn with Oak, cause it'd be great to see what you've been getting up to in this lesson.
And I'll see you again soon for lesson three.