This is the last video lecture in that section.
These will always be me practicing with you about what we've learned in current section the next lecture
will always be some practice problems for you to do on your own.
This will help you gain the confidence and experience in what we've been learning so let's do some more
practice to solidify everything.
Sue problem one write an algorithm that gets a number from the user from 1 to 7 and prints the corresponding
Dave.
We start that week with Monday.
So the first thing to do as outlined is always to see if we understand the problem first.
So if we start with Monday then that would mean Monday would correspond to the number 1 and 2 would
be Tuesday every Wednesday and so on.
So we end the week at Sunday which would be 7 so knowing this then we should start.
So let's say we have a variable day and we're going to set that to the user input.
Good day
user
next is we have to decide day of week it is.
So this will be our IF control statements.
So if de equals are equal to 1 then we know it's Monday right.
But it's
Monday.
Otherwise
if DE is to
you
in
Tuesday and so on.
So let's just finish all these other cases up.
If a will to read an
it's day
if Daisy go to four then
I could teach there is the
lies day see
five in
Friday
seven otherwise
day to sick it's
an
Saturday
all day
to seven Sunday
and then we're going to have one more actually.
So were I to say otherwise.
Otherwise it's just going to be an air raid.
Because what if the user included negative 1 or 10 Those don't correspond any day so we're just going
to put a general message that says
what it's that's not the
care.
So we're always going to be checking for errors in our code later on because either can easily type
something incorrectly.
So that's going to be one thing we're going to be looking out for future.
So we move on here to problem to
so choose says right now for them that sums all the odd numbers from 1 to 10 where n is a number from
the user output the result so
this is quite similar to some of the last problems we just did.
We're going to have an RE get in but it's the user user.
Give us some number N and then we have what we have or some in to start the summit in zero.
So sign some value zero for now.
Loop from 1 up to including in his arse.
Rumors are stopping condition
for
and we just read this in English for now but later on it'll actually be bit more formal.
So inside the loop.
We're going to say we want the current number that we're at or remember it counts up from 1 to an current
number
is called CNH
And then Rich check says the opposite of what we had before.
Before we had it had to be exactly divisible by two.
But now you want see and is not exactly divisible.
Visible by two then
then we just add
cn to the current Some
adze n
to this current sum and then reassign the sum to be that number.
Finally
put some.
That's it.
This makes sense.
To problem re
solve problem 3 says right now for them that takes in two numbers from the user the first number will
be the base and the second number and the second will be the exponent.
So this is like two to the power of some number base and power of some numbers.
So calculate the results of the base.
Number two the power of the exponent and output the result.
So
starch will need that base from the user.
So say first step is get the base get base the
and then get in touch
user
and then we have another variable actually that will help us is kind of like are some that we had before
but rushing in to say he which is short for power is two to one.
We'll see why in the second.
Let's go to Lou loop from one up to and including
in here in the loop.
We'll say he Zeek hoped he times be so here removing.
How many times removing
e times are 8.
So you count.
So let's say e was five.
So a count from one to five.
Say five times and then in the loop since he starts at 1.
Any number of times one is just that number.
So it'll start from let's say who's to the five so is the base.
So he would be 1 times 2.
And then we reassign it to be to be piece.
He is now two for the next and then two times two again which before.
So see why we needed that one here.
One kind of doesn't affect anything.
It'll just be the base in the first iteration and then you say two times two times two times too great
to think.
So two to five in that case would be three to in.
And then once it's over the loop is over and just say OK it's he right.
He has our results
hopefully that makes sense.
Again don't worry too much if we're not completely getting this yet.
We'll be doing a lot more examples in the following sections in fact be doing a lot more this kind of
stuff.
But I just wanted to give you a taste of what we'll be doing in the kinds of problems will be solved.
So see you in the next section.