WEBVTT

00:00.870 --> 00:04.530
This is the last video lecture in that section.

00:04.530 --> 00:10.950
These will always be me practicing with you about what we've learned in current section the next lecture

00:10.950 --> 00:15.430
will always be some practice problems for you to do on your own.

00:15.450 --> 00:22.350
This will help you gain the confidence and experience in what we've been learning so let's do some more

00:22.350 --> 00:25.860
practice to solidify everything.

00:27.510 --> 00:36.600
Sue problem one write an algorithm that gets a number from the user from 1 to 7 and prints the corresponding

00:36.810 --> 00:38.870
Dave.

00:38.960 --> 00:41.430
We start that week with Monday.

00:41.870 --> 00:51.310
So the first thing to do as outlined is always to see if we understand the problem first.

00:51.340 --> 00:59.620
So if we start with Monday then that would mean Monday would correspond to the number 1 and 2 would

00:59.620 --> 01:02.370
be Tuesday every Wednesday and so on.

01:02.370 --> 01:14.380
So we end the week at Sunday which would be 7 so knowing this then we should start.

01:14.550 --> 01:21.580
So let's say we have a variable day and we're going to set that to the user input.

01:21.950 --> 01:22.940
Good day

01:29.420 --> 01:29.860
user

01:37.150 --> 01:45.040
next is we have to decide day of week it is.

01:45.130 --> 01:52.990
So this will be our IF control statements.

01:53.370 --> 02:04.990
So if de equals are equal to 1 then we know it's Monday right.

02:06.410 --> 02:07.110
But it's

02:10.680 --> 02:15.870
Monday.

02:17.670 --> 02:18.840
Otherwise

02:23.100 --> 02:28.620
if DE is to

02:31.690 --> 02:32.210
you

02:37.300 --> 02:37.810
in

02:44.140 --> 02:48.610
Tuesday and so on.

02:48.630 --> 02:55.800
So let's just finish all these other cases up.

02:56.190 --> 03:05.100
If a will to read an

03:11.900 --> 03:13.370
it's day

03:24.870 --> 03:30.760
if Daisy go to four then

03:35.800 --> 03:37.960
I could teach there is the

03:48.320 --> 03:51.850
lies day see

03:54.900 --> 03:57.450
five in

04:04.420 --> 04:04.990
Friday

04:11.160 --> 04:14.180
seven otherwise

04:16.930 --> 04:21.700
day to sick it's

04:24.480 --> 04:25.020
an

04:32.020 --> 04:32.950
Saturday

04:42.570 --> 04:44.090
all day

04:46.810 --> 04:50.960
to seven Sunday

04:58.340 --> 05:00.570
and then we're going to have one more actually.

05:00.680 --> 05:03.100
So were I to say otherwise.

05:12.220 --> 05:15.500
Otherwise it's just going to be an air raid.

05:17.090 --> 05:28.050
Because what if the user included negative 1 or 10 Those don't correspond any day so we're just going

05:28.050 --> 05:30.690
to put a general message that says

05:36.570 --> 05:42.160
what it's that's not the

05:48.910 --> 05:49.420
care.

05:49.720 --> 05:57.130
So we're always going to be checking for errors in our code later on because either can easily type

05:57.130 --> 05:59.880
something incorrectly.

05:59.940 --> 06:06.620
So that's going to be one thing we're going to be looking out for future.

06:06.640 --> 06:10.910
So we move on here to problem to

06:15.300 --> 06:26.220
so choose says right now for them that sums all the odd numbers from 1 to 10 where n is a number from

06:26.220 --> 06:30.500
the user output the result so

06:34.030 --> 06:39.350
this is quite similar to some of the last problems we just did.

06:41.030 --> 06:51.810
We're going to have an RE get in but it's the user user.

06:51.940 --> 07:02.400
Give us some number N and then we have what we have or some in to start the summit in zero.

07:02.440 --> 07:06.790
So sign some value zero for now.

07:08.670 --> 07:17.890
Loop from 1 up to including in his arse.

07:17.990 --> 07:20.110
Rumors are stopping condition

07:27.700 --> 07:28.230
for

07:31.120 --> 07:37.630
and we just read this in English for now but later on it'll actually be bit more formal.

07:39.250 --> 07:42.100
So inside the loop.

07:43.710 --> 07:54.530
We're going to say we want the current number that we're at or remember it counts up from 1 to an current

07:54.630 --> 07:55.240
number

07:59.020 --> 08:00.050
is called CNH

08:02.800 --> 08:08.790
And then Rich check says the opposite of what we had before.

08:08.790 --> 08:13.070
Before we had it had to be exactly divisible by two.

08:13.090 --> 08:24.230
But now you want see and is not exactly divisible.

08:26.270 --> 08:32.410
Visible by two then

08:38.690 --> 08:39.800
then we just add

08:42.650 --> 08:44.720
cn to the current Some

08:48.810 --> 08:49.980
adze n

08:54.040 --> 09:03.230
to this current sum and then reassign the sum to be that number.

09:03.420 --> 09:04.020
Finally

09:07.090 --> 09:10.370
put some.

09:10.860 --> 09:15.280
That's it.

09:15.590 --> 09:16.700
This makes sense.

09:22.170 --> 09:24.670
To problem re

09:28.340 --> 09:35.440
solve problem 3 says right now for them that takes in two numbers from the user the first number will

09:35.440 --> 09:41.350
be the base and the second number and the second will be the exponent.

09:41.350 --> 09:48.530
So this is like two to the power of some number base and power of some numbers.

09:48.910 --> 09:51.520
So calculate the results of the base.

09:51.640 --> 09:55.550
Number two the power of the exponent and output the result.

09:55.610 --> 09:55.970
So

10:01.360 --> 10:06.070
starch will need that base from the user.

10:06.070 --> 10:16.430
So say first step is get the base get base the

10:24.440 --> 10:27.960
and then get in touch

10:31.200 --> 10:31.790
user

10:38.380 --> 10:46.440
and then we have another variable actually that will help us is kind of like are some that we had before

10:46.470 --> 10:54.870
but rushing in to say he which is short for power is two to one.

10:54.930 --> 10:58.290
We'll see why in the second.

10:58.510 --> 11:08.280
Let's go to Lou loop from one up to and including

11:19.380 --> 11:23.050
in here in the loop.

11:23.050 --> 11:33.650
We'll say he Zeek hoped he times be so here removing.

11:33.680 --> 11:37.520
How many times removing

11:41.090 --> 11:47.610
e times are 8.

11:47.680 --> 11:48.840
So you count.

11:48.940 --> 11:52.030
So let's say e was five.

11:52.190 --> 11:54.630
So a count from one to five.

11:54.670 --> 12:04.350
Say five times and then in the loop since he starts at 1.

12:04.540 --> 12:07.940
Any number of times one is just that number.

12:07.990 --> 12:15.840
So it'll start from let's say who's to the five so is the base.

12:15.870 --> 12:19.250
So he would be 1 times 2.

12:19.410 --> 12:22.400
And then we reassign it to be to be piece.

12:22.410 --> 12:31.470
He is now two for the next and then two times two again which before.

12:32.000 --> 12:34.130
So see why we needed that one here.

12:34.180 --> 12:36.300
One kind of doesn't affect anything.

12:37.820 --> 12:49.210
It'll just be the base in the first iteration and then you say two times two times two times too great

12:49.920 --> 12:51.590
to think.

12:51.970 --> 12:58.880
So two to five in that case would be three to in.

12:59.060 --> 13:07.640
And then once it's over the loop is over and just say OK it's he right.

13:07.770 --> 13:09.870
He has our results

13:12.760 --> 13:15.310
hopefully that makes sense.

13:17.310 --> 13:21.950
Again don't worry too much if we're not completely getting this yet.

13:22.310 --> 13:29.810
We'll be doing a lot more examples in the following sections in fact be doing a lot more this kind of

13:29.810 --> 13:30.360
stuff.

13:30.360 --> 13:38.130
But I just wanted to give you a taste of what we'll be doing in the kinds of problems will be solved.

13:38.590 --> 13:40.480
So see you in the next section.
