WEBVTT

00:00.330 --> 00:07.470
So let's use our takeaways we learned from The Last Lecture we really formalize our language into what

00:07.470 --> 00:10.480
is called pseudo.

00:10.730 --> 00:15.990
So it's starch.

00:16.200 --> 00:20.230
So we'll supreme one get two numbers from the user.

00:20.250 --> 00:23.790
One is the length of the base of a triangle.

00:23.910 --> 00:35.280
The other is the height of the trying to calculate the area of the triangle and output so let's say

00:36.760 --> 00:40.660
we use B for base.

00:40.750 --> 00:52.890
This is our let's call the variable and want to use the call sign as assignment and so use a signed

00:55.040 --> 00:57.380
the user inputs

00:59.960 --> 01:07.670
or the base trying.

01:07.740 --> 01:19.680
So this gets the input from the user and assigns it to our new variable The is just a shorthand that

01:19.680 --> 01:26.290
we understand as assignment in storing the value.

01:26.350 --> 01:31.620
So we do the same for each We'll call the heights.

01:31.690 --> 01:43.890
Each user inputs for the base or heights or the trying

01:50.490 --> 01:51.590
next.

01:52.430 --> 02:00.140
You say A is equal to A is the area.

02:00.140 --> 02:08.230
So do simple calculation times each then all over 2.

02:08.360 --> 02:15.100
So that will calculate the area.

02:15.350 --> 02:21.740
China and then simply all we have to do now is it.

02:21.830 --> 02:28.780
So output the.

02:28.890 --> 02:37.020
And that's our algorithm for calculating the area of trying pretty simple.

02:37.260 --> 02:46.240
And now notice we're really trying to formalize and make a shorthand of our algorithm.

02:46.290 --> 02:50.790
So this is what's called pseudo code.

02:50.860 --> 02:57.760
It's a combination of English because we don't know how to get input from a user yet.

02:58.000 --> 03:05.770
So we just use English and actual code that you might see in a C++.

03:05.780 --> 03:11.890
So here is the value that we get for the base of the triangle.

03:11.900 --> 03:18.240
Each is the height and a is the area.

03:18.470 --> 03:24.740
And again we'll use equals as the sign that.

03:24.860 --> 03:32.390
So this whatever this value evaluates to gets assigned to a

03:36.520 --> 03:39.700
A will have that value after this is over.

03:43.860 --> 03:46.190
And we'll be doing a lot more examples.

03:48.680 --> 03:53.530
Let's move on to problem to.

03:53.610 --> 04:04.730
So given the given three side lengths the triangle A B and C output whether the triangle is equal lateral

04:04.770 --> 04:14.000
which means all sides of the same Isosceles which means two sides of the same or scaling meaning none

04:14.000 --> 04:16.460
of the so

04:20.840 --> 04:25.720
here we know we need some kind of condition right.

04:25.880 --> 04:32.200
So we need to say are all of the sides equal.

04:32.400 --> 04:35.690
If so then it's an equilateral triangle.

04:36.750 --> 04:38.870
So how would you do that.

04:38.910 --> 04:46.800
Well let's just say if a

04:49.980 --> 04:55.930
is in parentheses here is equal to.

04:56.170 --> 04:58.110
We'll just use English here.

04:58.990 --> 05:01.630
He could to the

05:05.990 --> 05:15.890
and the is equal to see

05:18.300 --> 05:30.460
then we know that a is also equal to see because it be equal C and A equals B then A also has to equal

05:30.460 --> 05:39.070
C then we'll say one a is out put

05:43.180 --> 05:46.570
that it's lateral

05:51.790 --> 05:53.900
or All right.

05:57.390 --> 05:57.890
OK.

05:57.990 --> 06:15.140
So this whole thing is all line valuate to True or false and it evaluates true if B is equal to A and

06:15.320 --> 06:21.730
B is also a C and then if it is true then it will do this line.

06:21.840 --> 06:26.010
But that it's an equal try

06:29.340 --> 06:29.850
so.

06:29.920 --> 06:31.000
Otherwise

06:35.510 --> 06:35.810
if

06:41.360 --> 06:46.610
a is equal to B or

06:49.330 --> 06:59.070
A is equal to C or B is equal to C

07:05.380 --> 07:05.890
then

07:11.740 --> 07:21.850
it's at it's an sauce so it's right.

07:23.230 --> 07:23.890
So no.

07:23.940 --> 07:27.850
So notice here is that space.

07:27.870 --> 07:42.670
What does this saying it says if a is equal to B meaning these two sides are the same or azy could see

07:42.670 --> 07:50.070
meaning those two sides of the same or Veazey could see which means those two sides of the same.

07:50.200 --> 07:57.400
Any one of these conditions if they're true means that it's an isosceles triangle and there is here

07:57.400 --> 08:03.600
that they can't all be true because otherwise it would have done this.

08:03.970 --> 08:05.530
This first line right here

08:08.520 --> 08:18.430
so we know that they can't all be the same because it would have said with equal lateral trying.

08:18.570 --> 08:25.280
So we know only two or less are equal here.

08:26.280 --> 08:31.920
And there was also that we can you can actually change conditions together.

08:32.010 --> 08:33.320
So this is a condition.

08:33.330 --> 08:35.030
This artery here.

08:38.510 --> 08:40.360
Right there also.

08:40.390 --> 08:49.780
This is condition and this is also a condition in chaining.

08:49.870 --> 08:58.550
So either one of the either one of these is true then we'll do this again don't worry too much will

08:58.550 --> 09:05.100
go much more formally into into conditions later.

09:05.130 --> 09:10.320
But I just want to give you a little bit of exposure to it now so you'll have a better understanding

09:10.400 --> 09:11.020
later.

09:12.190 --> 09:13.780
So otherwise

09:21.410 --> 09:32.370
an output such output at it's scaley

09:36.860 --> 09:37.250
shreiking

09:42.180 --> 09:52.610
because now we know that none of them could be the same because otherwise if one or more were the same

09:52.700 --> 09:59.910
it would have been it would have done this condition great.

09:59.940 --> 10:11.030
So stips this if it's not all equal skips this if two are equal otherwise they don't just say it's descaling

10:11.150 --> 10:14.380
because none are equal.

10:14.390 --> 10:23.490
Hope you're sort of understanding now how how we're going to go about writing these algorithms and solving

10:23.490 --> 10:24.530
these problems.

10:31.310 --> 10:35.660
So let's move on to three

10:41.410 --> 10:46.560
Supremes three says output all even numbers from 1 to 100.

10:47.840 --> 11:01.200
So we need to go through all of the numbers somehow and see if they are even in if they are we have

11:01.200 --> 11:13.540
the output that number so for this we'll need what we talked about last time which is a so we're some

11:13.550 --> 11:22.550
say loop from 1 to 100.

11:22.780 --> 11:29.350
And notice here that this is also a condition but this is a bit of a different condition than the one

11:29.350 --> 11:32.070
we had here.

11:33.570 --> 11:36.840
This is actually the stopping condition

11:40.490 --> 11:48.820
for our if he didn't have this condition or you wrote it incorrectly it could loop forever.

11:48.830 --> 11:56.120
Remember what I said about computers and them being really dumb computer only does what you tell it

11:56.120 --> 11:56.460
to do.

11:56.460 --> 12:06.270
So if you told them to do or told it to loop infinitely it will loop infinity which is not what you

12:06.270 --> 12:07.230
want.

12:07.380 --> 12:10.840
So reading this condition is very important.

12:12.170 --> 12:18.600
And the conditions for loops are always the stopping condition to do it.

12:18.620 --> 12:23.980
Until this is false.

12:24.100 --> 12:28.770
So now what would we need here.

12:28.780 --> 12:34.470
So we need the current number that were at.

12:34.480 --> 12:37.080
So this is seen.

12:37.420 --> 12:40.080
Will just say is the current number.

12:40.120 --> 12:41.600
Not sure how we get that yet.

12:41.680 --> 12:45.930
But it's whatever the next number is.

12:45.950 --> 12:49.180
So it will start at 1 and they go that 2 in and so on.

12:50.270 --> 12:54.280
So we have the current number and then we'll say

12:57.640 --> 13:02.850
if C-n is exactly

13:05.300 --> 13:18.280
divisible by 2 meaning if it's a whole the whole number it's an actual number so 10 divided by two is

13:18.330 --> 13:28.500
five but nine divided by two is 4.5 great which is not a whole number.

13:30.340 --> 13:40.280
So you want it to exactly divisible by two just to divide something by two you know.

13:42.450 --> 13:43.520
3a then

13:46.600 --> 13:50.340
we'll be pre-suppose output.

13:51.470 --> 13:57.080
The current number of your kids we know the current number is divisible by two.

13:57.080 --> 14:06.520
In this case we don't need it Kate another case because we just want to continue on with the loop.

14:06.520 --> 14:19.660
It's not divisible by two so hopefully you're understanding how this is how this is working.

14:20.960 --> 14:22.910
So you have your stopping condition for you.

14:22.910 --> 14:27.090
Luke So we're going to loop until we get to 100.

14:27.960 --> 14:37.670
We somehow get the current number that we're at and then you say if that current number that we're at

14:37.670 --> 14:45.190
is divisible by 2 then we just output that number.

14:45.780 --> 14:47.230
That's all there is to that.

14:51.240 --> 14:54.320
Sue let's move on to problem for

14:56.940 --> 15:03.410
so get the number from the user and output output.

15:03.620 --> 15:10.460
Run up put the sum of all the numbers from one up to and including the inputted number

15:13.420 --> 15:16.170
so we understand the problem first.

15:16.270 --> 15:23.060
We'll get a number from the user and then we'll loop from one up to that number.

15:25.270 --> 15:42.300
And create some from 1 to say and say so in is the number from the user.

15:42.430 --> 15:45.510
The user will input a number to us.

15:45.670 --> 15:52.050
So let's say the sum is something and the sum will start at zero.

15:52.060 --> 15:57.440
So we'll sign our new variable sum to be zero.

16:00.610 --> 16:14.390
Next he will say the from 1 to up to including.

16:14.990 --> 16:33.160
This is our stopping condition for stopping just like we have in problem 3.

16:33.240 --> 16:35.220
Then it's pretty simple.

16:35.460 --> 16:39.550
Say some is equal to

16:42.170 --> 16:42.840
never.

16:43.040 --> 16:46.220
Well for this we need again the

16:49.030 --> 16:52.850
hurt number and Boole's hurt never

16:56.290 --> 16:58.000
like we had in problem three.

16:58.110 --> 17:07.310
Some will be equal to some equals some plus the number.

17:07.350 --> 17:18.220
So whatever the sum was for just add the current number to this up and then sign that value back to

17:18.240 --> 17:23.800
some so we're just adding on CN to this every time.

17:24.000 --> 17:32.980
And those also didn't mention four but I'm indenting four and five here from three.

17:33.060 --> 17:41.280
This means that four and five are inside this loop so the loop only pertains to 4 and 5 steps sporran

17:41.320 --> 17:42.950
by.

17:43.070 --> 17:47.060
And this is important because in Step Five are outside the loop.

17:47.060 --> 17:48.380
Say we're done now.

17:49.240 --> 17:50.490
And then we'll say out.

17:50.560 --> 17:53.470
But some

17:57.250 --> 17:57.960
in that's it

18:01.020 --> 18:02.720
we're done with this.

18:02.860 --> 18:09.600
So I hope this is starting to set in a little bit bring you some more examples and in the next lecture

18:10.100 --> 18:13.770
to hopefully solidify what we've been learning so far.
