1
00:00:04,720 --> 00:00:08,020
Alright so let's go over the challenge
that I introduced at the end of the

2
00:00:08,020 --> 00:00:12,340
previous video. If you recall, the
challenge was to rewrite the program so

3
00:00:12,340 --> 00:00:17,320
that it tests for a correct guess first.
So to do that we need to start by

4
00:00:17,320 --> 00:00:21,120
changing line six. At the moment it's
checking the guess is not equal

5
00:00:21,120 --> 00:00:25,520
to answer, so we need to change the not equal to become equal to. So we're now checking,

6
00:00:25,520 --> 00:00:29,059
specifically, if guess is equal to
answer, then we're going to change that

7
00:00:29,060 --> 00:00:34,680
if it is. Then I come down here and take
a copy of this code, and I'm going to

8
00:00:34,680 --> 00:00:40,720
paste it under, we indent it on line 7.
So if guess is equal to answer, we're

9
00:00:40,730 --> 00:00:44,140
printing out the message "You've got it
first time", and the code here is going to

10
00:00:44,140 --> 00:00:48,040
remain the same, if guess is less than answer. I'm just going through the process of checking.

11
00:00:48,040 --> 00:00:50,840
In fact, I should really have
just cut that out altogether because I

12
00:00:50,840 --> 00:00:54,800
copied it, but that line is no longer
needed anymore. So I'm going to delete

13
00:00:54,800 --> 00:00:58,040
that, and we're doing that for the
scenario where they haven't got the

14
00:00:58,040 --> 00:01:02,780
answer right. So what we need to do is
remove this else altogether, and we need

15
00:01:02,780 --> 00:01:08,540
to come down here, after line 7, and
go back to the first indentation level

16
00:01:08,540 --> 00:01:13,429
and put an else colon there. And again,
what's happening here if guess is

17
00:01:13,429 --> 00:01:17,780
not equal to answer, then the else
clause gets executed and the code

18
00:01:17,780 --> 00:01:22,159
starting from line 9 will then go
through and get executed. And obviously,

19
00:01:22,159 --> 00:01:26,179
in the case of the guess equaling the
answer, which is the comparison on line

20
00:01:26,179 --> 00:01:31,100
6, if that's the case, only line 7
is going to be executed. So this is

21
00:01:31,100 --> 00:01:34,560
a third way to write the program and it
still does exactly the same thing.

22
00:01:34,560 --> 00:01:38,360
It's just phrased differently, just like you
can do with human languages.

23
00:01:38,360 --> 00:01:42,679
So here we're checking for a correct guess first.
Now it doesn't really matter which way

24
00:01:42,680 --> 00:01:45,860
round you do it. There's no necessarily
correct way of doing it.

25
00:01:45,860 --> 00:01:50,440
We're looking for the result here or for the solution, so if you manage to get the solution, congratulations.

26
00:01:50,440 --> 00:01:54,760
So let's just confirm we've
got this right. We'll just do a quick test.

27
00:01:54,760 --> 00:01:58,320
And firstly, I'll test to see whether
the number is correct, works,

28
00:01:58,320 --> 00:02:05,600
"You got it right first time" which is good. Lets do a
test where it's 1, "Please guess higher".

29
00:02:05,600 --> 00:02:08,880
We'll do 9. You can see that code has
been executed,

30
00:02:08,880 --> 00:02:15,060
and we'll do a test where we're starting off with a
high value, 9, "Please get lower", 1,

31
00:02:15,060 --> 00:02:19,020
"You have not guessed correctly". We'll just do one
more scenario, start with 1 again,

32
00:02:19,020 --> 00:02:23,420
we'll do 5. So clearly the code is still
working. Alright, so do make sure you

33
00:02:23,420 --> 00:02:26,600
test the programme as I've done, even
though I haven't done a complete test,

34
00:02:26,600 --> 00:02:30,060
and in the next video we're going to
start looking at more complex conditions.

35
00:02:30,060 --> 00:02:33,080
See you in the next video.

