WEBVTT

0
00:00.080 --> 00:01.280
How did he get on?

1
00:01.610 --> 00:06.830
Hopefully, you managed to complete the project and you're just here to check through the solution.

2
00:06.860 --> 00:13.520
Now, if you haven't given it a proper go and I mean at least an hour tackling this, then go back,

3
00:13.520 --> 00:14.510
keep going,

4
00:14.510 --> 00:17.540
it's only when you struggle that you actually get better.

5
00:17.540 --> 00:21.710
You can watch me type code all day long, and it's not going to make you a better programmer.

6
00:21.710 --> 00:23.840
So I know you're going to try really hard,

7
00:23.840 --> 00:29.920
and I want you to try really, really extra hard and make sure that you can complete each of these projects

8
00:29.920 --> 00:30.850
by yourself.

9
00:31.660 --> 00:36.940
Now, when you're creating a new project from scratch, like we're doing right now, it can seem a little

10
00:36.940 --> 00:39.670
bit intimidating staring at a blank screen.

11
00:39.700 --> 00:45.730
So the first thing to do is to just divide up the project into individual components.

12
00:45.730 --> 00:51.220
So while you're playing this game, you can see that there are different bits of it that we need to

13
00:51.220 --> 00:52.180
complete, right?

14
00:52.180 --> 00:56.440
The first one is printing all the starting parts of the game.

15
00:56.440 --> 01:02.560
The next one is trying to figure out how to set this difficulty level, getting the user to type in

16
01:02.560 --> 01:07.630
a word easy or hard, and then changing the number of attempts based on that.

17
01:08.650 --> 01:16.990
We can already start thinking about maybe we need to make a function to set difficulty, and then we

18
01:16.990 --> 01:19.340
need to let the user make a guess, right?

19
01:19.340 --> 01:21.110
So they're going to guess a number.

20
01:21.110 --> 01:23.570
So let's say I'm going to type in 50.

21
01:23.570 --> 01:30.290
And then we have to somehow check that guess against the number that was originally selected, and then

22
01:30.290 --> 01:32.690
check to see if it's too low or too high.

23
01:32.780 --> 01:36.230
So now we have some additional parts of our program.

24
01:36.230 --> 01:36.410
Right?

25
01:36.410 --> 01:44.860
We need some sort of way of choosing a random number between 1 and 100.

26
01:44.860 --> 01:48.160
So that's the first thing that's probably going to happen in our code.

27
01:48.160 --> 01:51.100
We need to have a function to set difficulty.

28
01:51.100 --> 01:58.780
We probably need some sort of functionality to let the user guess a number.

29
02:00.130 --> 02:07.520
And we'll also want to check that number that they've guessed against the number that we originally

30
02:07.520 --> 02:09.830
had to see if it's too high or too low.

31
02:09.830 --> 02:19.040
So probably a function to check users' guess against actual answer.

32
02:19.340 --> 02:25.250
Now notice how every single time I make a guess, my number of attempts go down.

33
02:25.250 --> 02:27.350
So we also need to track that, right?

34
02:27.380 --> 02:35.820
Track the number of turns and reduce by 1 if they get it wrong.

35
02:36.810 --> 02:41.790
Now it's looping back again to this stage where we're making another guess.

36
02:41.790 --> 02:44.970
So if 50 was too high, then maybe we'll guess 25.

37
02:45.000 --> 02:49.680
We have to have some sort of way of repeating this part of the code, right?

38
02:50.850 --> 02:55.870
We're going to repeat it as long as they have attempts left and they are wrong.

39
02:56.080 --> 03:01.240
Now if, however, they get it right, so I think I have a good chance of getting it right,

40
03:01.240 --> 03:04.270
so if 25 is still too high, let's try 12.

41
03:04.330 --> 03:05.290
And there we go.

42
03:05.290 --> 03:07.840
When I get the answer right, it tells me, "You got it!

43
03:07.840 --> 03:09.280
The answer was 12."

44
03:09.280 --> 03:16.120
So now we've got some of the basic parts of our code down in comments, and we can start thinking about

45
03:16.120 --> 03:17.320
how to write it out.

46
03:17.320 --> 03:17.860
Right?

47
03:18.170 --> 03:23.720
Let's start by tackling the easiest one, which is choosing a random number between 1 and 100.

48
03:23.750 --> 03:30.890
All we have to do for this one is just to import the Random Module, or even better yet, from the random

49
03:30.890 --> 03:34.460
module, import the randint function.

50
03:35.270 --> 03:39.200
Now inside our code we can simply just use randint.

51
03:39.230 --> 03:46.740
We can say the answer is equal to a randint() that is between 1 and 100.

52
03:46.740 --> 03:54.120
And of course, remember that randint() includes A and B, so both 1 and 100 can show up.

53
03:54.900 --> 03:58.830
In addition to this, we probably have to give the user some of these messages.

54
03:58.830 --> 04:01.320
So I'm just going to copy some of these messages.

55
04:01.320 --> 04:05.940
So I'm going to print, "Welcome to the Guessing Game!"

56
04:05.940 --> 04:13.690
And also I'm going to print that "I'm thinking of a number between 1 and 100," like that.

57
04:13.780 --> 04:17.110
So now we've got an answer that they need to guess,

58
04:17.110 --> 04:20.080
and we've got a little bit of starting text for them.

59
04:20.080 --> 04:26.050
The next easiest thing in this is to figure out a way of letting the user guess a number.

60
04:26.050 --> 04:33.090
So we know that we'll need an input to ask them to make a guess, and we can use that as the prompt.

61
04:33.090 --> 04:37.830
And then we're going to have to save their guess and convert it to an integer.

62
04:37.860 --> 04:40.560
So they're going to be typing a number here right.

63
04:40.560 --> 04:42.900
And we'll call this guess.

64
04:43.500 --> 04:46.320
Now the user is able to guess a number.

65
04:46.680 --> 04:55.030
And we now have to figure out some sort of way of checking the user's guess against the actual answer.

66
04:55.210 --> 05:02.140
This is probably a good time to create a function, so why don't we go up to the very top and create

67
05:02.140 --> 05:03.280
our function here?

68
05:03.310 --> 05:10.660
We'll call this check_answer(), and we're going to pass in the user's guess and the actual_answer() in

69
05:10.660 --> 05:13.510
order to achieve this checking functionality.

70
05:14.200 --> 05:20.480
So in this case we're going to check to see if the guess is greater than the answer,

71
05:20.510 --> 05:22.490
well in this case it's too high, right?

72
05:22.490 --> 05:25.160
So we'll just print, "Too high."

73
05:25.880 --> 05:29.720
Now what if the guess was actually less than the answer?

74
05:29.720 --> 05:34.250
Still not equal to the answer, but in this case it's too low.

75
05:34.790 --> 05:38.210
So now the final condition is they actually got it right.

76
05:38.210 --> 05:43.980
So you could write elif guess is equal to answer, but you could also just use else because there's

77
05:43.980 --> 05:45.480
no other possibilities.

78
05:45.990 --> 05:49.980
This else statement catches the moment when they actually get it right.

79
05:50.370 --> 05:53.460
So in this case, we're going to print what we have here,

80
05:53.460 --> 05:55.050
and then we're going to print out the answer.

81
05:55.050 --> 06:00.390
So of course we're going to replace that with whatever the actual answer is and turn this into an

82
06:00.390 --> 06:00.930
f-string.

83
06:01.350 --> 06:03.720
So now that's that step done,

84
06:03.720 --> 06:07.480
let's think about what else is easy that we can knock off the list.

85
06:07.780 --> 06:10.510
Let's make a function to set the difficulty.

86
06:10.690 --> 06:17.710
So up here, in addition to our check_answer() function, I'm going to create this other function, some

87
06:17.710 --> 06:19.720
way of setting the difficulty.

88
06:19.720 --> 06:22.630
So let's call this set_difficulty().

89
06:22.780 --> 06:25.720
And it's probably not going to take any inputs,

90
06:25.720 --> 06:28.330
it's just going to do some sort of action.

91
06:28.480 --> 06:33.680
So when we first start off the game it already asks us to choose a difficulty.

92
06:33.680 --> 06:39.380
So I'm going to copy this text and I'm going to put that into an input.

93
06:39.830 --> 06:43.280
Choose a difficulty, easy or hard.

94
06:43.340 --> 06:49.130
And then we're going to save this probably into a variable which I'll call level.

95
06:49.130 --> 06:52.010
So the level of difficulty that they want.

96
06:52.190 --> 06:58.230
Now if this level that they chose was equal to easy,

97
06:58.230 --> 07:04.710
well, in this case, we want to set the number of attempts that they have to ten,

98
07:04.710 --> 07:06.450
So they have 10 attempts.

99
07:06.450 --> 07:12.720
But on the other hand, if they chose hard, then they only have 5 attempts.

100
07:12.720 --> 07:18.660
So this is probably a really good time for creating a global constant.

101
07:18.660 --> 07:22.130
So we really saw this in the previous lesson on scope,

102
07:22.130 --> 07:28.310
but this is a really nice thing because it means if we create this global constant at the very top,

103
07:28.310 --> 07:35.180
then if we want to switch around how our game works, we can really easily access these constants by

104
07:35.180 --> 07:37.250
just scrolling to the top of the page.

105
07:37.280 --> 07:42.050
Let's call the first one, EASY_LEVEL_TURNS.

106
07:42.050 --> 07:51.240
So the number of turns you get on easy, which is going to be 10, and then we'll have HARD_LEVEL_TURNS,

107
07:51.240 --> 07:53.370
and this is going to be equal to 5.

108
07:53.580 --> 07:58.050
Now I've got these two constants which is global,

109
07:58.050 --> 08:02.790
And I can use it inside any of my functions or basically anywhere on this page.

110
08:02.910 --> 08:11.290
If the level is easy, I'm going to set the number of turns to equal the EASY_ LEVEL_TURNS.

111
08:11.290 --> 08:13.510
So this is going to be a number, right?

112
08:13.990 --> 08:14.620
Else,

113
08:14.620 --> 08:20.920
so if they chose hard instead then turns should probably be the HARD_LEVEL_TURNS.

114
08:20.920 --> 08:23.380
Now setting it here is no use,

115
08:23.380 --> 08:26.230
I actually need it inside my game.

116
08:26.740 --> 08:33.290
So now going back in my game, I need to let the user know how many number of attempts, how many turns

117
08:33.290 --> 08:34.520
they actually get.

118
08:34.520 --> 08:40.760
To start off, I'm going to use a print statement that just prints the number of attempts they have

119
08:40.760 --> 08:43.310
remaining, and it's not always going to be 5,

120
08:43.310 --> 08:46.670
sometimes it's going to be 5, sometimes it's going to be 10.

121
08:46.670 --> 08:51.710
So what I'll need is some sort of way of tracking this number of turns.

122
08:51.710 --> 08:52.190
Right?

123
08:52.280 --> 08:55.670
But how do we know how many turns they get?

124
08:55.670 --> 08:59.010
Well, it depends on what they chose here, right?

125
08:59.370 --> 09:04.410
If they had chosen hard, then turns should be equal to the HARD_LEVEL_TURNS.

126
09:04.410 --> 09:07.410
If they chose easy, it should be equal to the EASY_LEVEL_TURNS.

127
09:07.440 --> 09:13.470
So instead of using this as some sort of global variable which I have to change inside here, which

128
09:13.470 --> 09:20.770
would require me saying global and then turns so that I can access this particular variable and change

129
09:20.770 --> 09:22.720
it inside these steps,

130
09:22.930 --> 09:30.010
it would be much, much better if I just returned these values as an output from this function.

131
09:30.370 --> 09:38.140
If this is set as return, then I can simply call this function set_difficulty(), which is going to trigger

132
09:38.140 --> 09:39.160
this input.

133
09:39.160 --> 09:45.420
And then once the user is set it, then the output is going to be the actual number of turns they have,

134
09:45.420 --> 09:50.730
and I can now use it inside this print statement to show them how many turns they have.

135
09:51.480 --> 09:58.230
Now, I've already written quite a bit of code actually, and it's probably a good time to run the code.

136
09:58.590 --> 10:04.410
While I'm testing my code, it's probably a good idea to actually see what the answer is, so we can

137
10:04.410 --> 10:09.740
add a bit of testing code that just prints out what the actual answer was selected as.

138
10:09.740 --> 10:15.020
And if we run the code now, you can see we've got the starting part pretty much down.

139
10:15.020 --> 10:16.640
Welcome to the number guessing game.

140
10:16.640 --> 10:18.830
I'm thinking of a number between 1 and 100.

141
10:18.830 --> 10:20.750
And then we've got our little hint here.

142
10:20.750 --> 10:22.790
So we have to make a guess.

143
10:22.790 --> 10:25.430
So let's say I guessed 50.

144
10:26.090 --> 10:29.000
Now it's asking us to choose a difficulty.

145
10:29.000 --> 10:31.310
So I've already got a little bit of a problem here.

146
10:31.310 --> 10:38.280
I should actually have this, before the other part, so I should choose the difficulty and then make

147
10:38.280 --> 10:38.910
a guess.

148
10:38.910 --> 10:43.110
So now let's stop and run and see if we've fixed that bug.

149
10:43.110 --> 10:44.040
And you can see,

150
10:44.040 --> 10:44.850
yep, indeed.

151
10:44.850 --> 10:47.460
It asks us for a difficulty first.

152
10:47.460 --> 10:49.170
So I'm going to choose easy.

153
10:49.170 --> 10:51.810
And it tells me that I've got 10 attempts remaining.

154
10:51.810 --> 10:53.610
And then to make a guess.

155
10:53.610 --> 10:58.710
And if I choose hard instead, then it tells me I've got 5 attempts.

156
10:58.710 --> 11:03.660
Now, if while you're playtesting this game and you realize that actually 5 is not enough, then

157
11:03.660 --> 11:10.710
all you have to do is scroll to the very top of the game, change this one global variable here, and

158
11:10.710 --> 11:14.250
all your changes you know will be reflected in the code below.

159
11:15.300 --> 11:17.040
Now let's get back to our game.

160
11:17.040 --> 11:20.400
Let's say I make a guess and our code ends, right?

161
11:20.460 --> 11:25.090
Even though I've got my check_answer(), it's not actually being called anywhere.

162
11:25.090 --> 11:28.660
So let's go ahead and call that function, check_answer(),

163
11:28.660 --> 11:32.530
and then we can pass in the user's guess that they made at this step,

164
11:32.530 --> 11:36.970
and we can also pass in the correct answer which comes from here.

165
11:36.970 --> 11:39.310
So let's run our code again.

166
11:40.570 --> 11:42.430
So I'm going to choose the easy mode

167
11:42.430 --> 11:44.440
and I'm going to make a guess.

168
11:44.560 --> 11:48.710
Now 50 is too high because I can actually see the answer.

169
11:48.830 --> 11:49.850
So that works,

170
11:49.850 --> 11:51.650
but I can't guess

171
11:51.650 --> 11:53.390
again, it's not letting me.

172
11:53.390 --> 11:56.090
It's actually ended the program.

173
11:56.090 --> 12:02.570
So we probably have to tackle this particular TODO if we actually want to get the right functionality.

174
12:02.570 --> 12:06.980
How do we get the guessing functionality to repeat if they get it wrong?

175
12:07.820 --> 12:13.320
So that, as you might have guessed, is probably going to require some sort of while loop.

176
12:13.380 --> 12:19.710
While they've gotten it wrong, we probably should go and let them make a guess again.

177
12:19.860 --> 12:22.920
These parts will definitely need to be repeated.

178
12:23.370 --> 12:25.290
So let's create a while loop.

179
12:25.320 --> 12:30.150
What are we going to check in our while loop to make sure that it keeps on going?

180
12:30.180 --> 12:36.580
Well, the thing that we're trying to aim for is to get the user to guess the actual answer.

181
12:36.610 --> 12:44.020
If we set the while condition as while guess is not equal to answer, then that pretty much guarantees

182
12:44.020 --> 12:49.390
that these lines of code will keep going until the user actually gets the right answer.

183
12:50.470 --> 12:53.260
Now however, when we do this, we get an error.

184
12:53.260 --> 13:00.510
Well, because guess hasn't been declared yet, so why don't we declare it outside of the while loop

185
13:00.510 --> 13:03.450
and simply just create it as a variable?

186
13:03.450 --> 13:05.730
So we'll set that to equal 0

187
13:06.150 --> 13:09.480
Now at the moment this is a global variable.

188
13:09.480 --> 13:10.770
This is a global variable.

189
13:10.770 --> 13:18.000
So it's probably a good idea to put our game functionality inside its own function.

190
13:18.000 --> 13:21.960
So we can create a new function here which I'll call game(),

191
13:21.980 --> 13:29.990
and now we'll need to call and trigger this game() inside the global scope if we actually want this to

192
13:29.990 --> 13:30.890
be carried out.

193
13:32.090 --> 13:37.280
So now that we've done all of this hard work, let's run our code and let's try it out.

194
13:39.380 --> 13:41.180
Let's go for easy.

195
13:41.180 --> 13:44.180
And I'm going to start off by guessing 50

196
13:44.180 --> 13:48.410
as always, 50 is too low, so I'm going to go for the next number.

197
13:48.410 --> 13:51.830
Let's try a number that's a bit too high 95, Too high.

198
13:51.890 --> 13:53.750
Now what if I actually get it right?

199
13:53.750 --> 13:55.640
Well it tells me you got it.

200
13:55.640 --> 14:01.760
So the only thing that we're not really doing is tracking the number of turns so that we tell them you

201
14:01.760 --> 14:04.880
have 10 attempts, you have 9 attempts, you have 0 attempts.

202
14:04.880 --> 14:07.280
And if they get 0, then they're going to lose,

203
14:07.280 --> 14:14.070
right? Here we have this print statement that runs only once because it's not inside the while loop.

204
14:14.070 --> 14:21.180
So let's tackle our final TODO to track the number of turns and reduce it by 1 if they get it wrong.

205
14:21.180 --> 14:25.050
Now where do we know that the user got it wrong?

206
14:25.050 --> 14:31.590
Well, inside the check_answer() function, if it's too high, if it's too low, then we have to deduct

207
14:31.590 --> 14:33.270
the number of turns they have.

208
14:33.270 --> 14:35.560
But if they got it then we don't.

209
14:35.590 --> 14:42.070
One way of tackling this is again creating a global variable called turns,

210
14:42.070 --> 14:45.070
set it to start off at 0,

211
14:45.610 --> 14:54.520
and then inside this function, we simply just say, turns - = 1, and also turns - = 1,

212
14:54.520 --> 14:56.770
when it's too low or too high.

213
14:57.070 --> 15:05.990
Now because this is a global variable, we again would need to say global turns in order to use it inside

214
15:05.990 --> 15:06.980
our function.

215
15:06.980 --> 15:13.580
But as I mentioned, this is not a good idea because it means that you're modifying the global function

216
15:13.580 --> 15:15.470
within a local scope.

217
15:15.500 --> 15:21.500
How can we achieve the same functionality without having to use a global variable?

218
15:21.590 --> 15:28.050
Well, we could instead, just pass in the number of turns that we currently have,

219
15:28.050 --> 15:35.610
and then inside our function, we can return the number of turns- 1.

220
15:35.760 --> 15:38.070
And we can do the same down here.

221
15:41.550 --> 15:50.510
So now when we call this function check_answer(), we can pass in the current number of turns, which remember

222
15:50.510 --> 15:53.510
got set by the set_difficulty() function,

223
15:53.510 --> 16:01.460
and we can pass that in into here. Because it's not immediately obvious that this function actually

224
16:01.460 --> 16:02.780
has an output,

225
16:02.870 --> 16:07.280
it's probably a good idea to add a docstring to this function.

226
16:07.640 --> 16:10.100
Remember the three quotes?

227
16:10.100 --> 16:23.070
And then in between we're going to say, """Checks answer against guess, returns the number of turns remaining."""

228
16:24.570 --> 16:32.070
Now when we actually call check_answer(), you can see that this is what actually happens and that we

229
16:32.070 --> 16:39.640
have a return that we can be aware of. If this is going to be the number of turns remaining, then we

230
16:39.640 --> 16:47.770
can save that to this variable turns so that we update this local variable every time we check the answer.

231
16:48.970 --> 16:51.520
Now this part is a little bit mind blowing.

232
16:51.520 --> 16:57.280
So you might actually want to put this through Python Tutor and step through it, step by step, to see

233
16:57.280 --> 17:04.430
what's actually going on and how this turns variable is being updated by the output from this function.

234
17:04.430 --> 17:08.510
If you're totally happy with what's going on, then feel free to keep going.

235
17:09.860 --> 17:12.350
So now let's check out our code.

236
17:12.860 --> 17:16.940
Now what if I actually ran my number of turns down to 0?

237
17:16.940 --> 17:20.870
So let's try hard because this is only going to give us 5 attempts.

238
17:20.870 --> 17:28.170
So let's say I guessed 50 and then 70, and then I'm just going to put in some random numbers so that

239
17:28.170 --> 17:31.530
I end up with no remaining guesses.

240
17:32.430 --> 17:35.160
You can see it's actually not stopping me, right?

241
17:35.160 --> 17:41.100
And also for some reason, we have a bug where the number of attempts we have remaining is not actually

242
17:41.100 --> 17:42.150
being printed.

243
17:42.150 --> 17:44.160
So let's address that issue.

244
17:44.160 --> 17:50.530
Well, if we want it to happen every time and repeat, it's going to need to go into the while loop.

245
17:50.860 --> 17:57.550
So instead of printing our number of turns here, why don't we print it here inside the while loop instead?

246
17:58.090 --> 18:00.820
So let's make sure the indentation is correct.

247
18:00.820 --> 18:03.280
And now let's try it again.

248
18:06.400 --> 18:08.560
So I have 5 attempts remaining,

249
18:08.560 --> 18:09.760
let's make a guess.

250
18:09.760 --> 18:15.270
I have 4 attempts remaining. And notice how it's counting it down,

251
18:15.270 --> 18:16.020
3,

252
18:16.020 --> 18:16.470
2,

253
18:16.470 --> 18:17.010
1.

254
18:17.010 --> 18:21.570
This should be my last guess, but notice how it actually keeps on going,

255
18:21.570 --> 18:23.190
It doesn't stop the game.

256
18:23.190 --> 18:26.820
I can keep going and it's going into negatives now.

257
18:26.820 --> 18:28.590
So how can we fix this?

258
18:28.830 --> 18:34.800
We need some sort of way of tracking when this number of turns goes down to 0,

259
18:34.800 --> 18:39.430
and when that happens, we have to stop the game and tell them that they've lost.

260
18:39.550 --> 18:48.550
Why don't we create an if statement, check if the number of turns is equal to 0, and print something.

261
18:48.550 --> 18:51.460
Let's check the actual final version.

262
18:51.460 --> 18:53.320
Let's see what happens in this case.

263
18:53.320 --> 18:57.610
When I run out of goes, I make a guess,

264
18:57.610 --> 19:00.770
it's too low, and it tells me, "You've run out of guesses.

265
19:00.770 --> 19:01.880
You lose."

266
19:01.880 --> 19:04.400
We can print that here as well,

267
19:06.020 --> 19:08.720
but notice how if we run the code as it is,

268
19:08.720 --> 19:13.490
so let's just keep guessing the same number until I run it down to 1.

269
19:13.490 --> 19:15.200
So now I make a guess,

270
19:15.200 --> 19:21.020
it tells me, "You've run out of guesses, you lose," but it's still letting me keep going even though I've

271
19:21.020 --> 19:21.770
lost.

272
19:21.920 --> 19:30.750
How can we make our game end? Well, luckily we've got our game inside a function which is being called

273
19:30.750 --> 19:32.100
at the very beginning.

274
19:32.130 --> 19:40.110
Now remember that with functions you have the return keyword you can return with an output, or you

275
19:40.110 --> 19:44.820
can just write return for it to exit and end the function.

276
19:45.600 --> 19:52.390
So now with that return keyword in place once I run out of turns, see what happens.

277
19:54.790 --> 19:56.590
It stops and it doesn't

278
19:56.590 --> 19:58.480
let me guess anymore.

279
19:59.920 --> 20:00.670
Perfect.

280
20:00.670 --> 20:02.230
We've managed to get that right.

281
20:03.100 --> 20:08.260
The final thing that we're still missing is this prompt for the user to guess again.

282
20:08.290 --> 20:09.760
Now, this is kind of optional.

283
20:09.760 --> 20:12.910
It depends on your own feel for the user experience.

284
20:12.920 --> 20:15.170
I think it makes sense to say, "It's too low.

285
20:15.170 --> 20:18.140
Guess again," because it's kind of telling them to do something.

286
20:18.140 --> 20:22.790
Although this, 'Make a guess' also prompts them to make a guess so you can have it,

287
20:22.790 --> 20:23.810
you don't have to.

288
20:23.810 --> 20:30.620
If you wanted to have that, then you probably actually have to check that they still have turns remaining,

289
20:30.620 --> 20:38.880
and if they do, then make sure that the guess is not equal to the answer so they haven't got it right

290
20:38.880 --> 20:40.230
within this turn.

291
20:40.230 --> 20:43.140
And then to print that guess again.

292
20:44.340 --> 20:49.260
So now every time they get it wrong, but they still have remaining guesses,

293
20:49.260 --> 20:54.540
it should say, 'Too low. Guess again,'  or 'Too high. Guess again.

294
20:54.720 --> 21:00.810
But if they actually get it right then it says you got it without asking them to guess again.

295
21:01.300 --> 21:04.870
Now we've pretty much completed this code.

296
21:04.900 --> 21:10.360
Of course, you could have added additional art, so you could have created an art.py, and then

297
21:10.360 --> 21:16.630
used the text to ASCII generator to create an ASCII art.

298
21:16.630 --> 21:20.080
And then back in here we could have imported it,

299
21:22.390 --> 21:25.590
and we could put that at the very beginning of the game.

300
21:25.710 --> 21:30.240
But the rest of the customization is basically your own, right?

301
21:30.240 --> 21:36.570
You're free to do whatever it is that you want to and to change the wording, to change the text.

302
21:36.570 --> 21:43.830
The really important part was that you were able to play this game, understand how it worked, and

303
21:43.830 --> 21:48.870
then break down the problem into smaller pieces that you could tackle one by one.

304
21:48.880 --> 21:56.590
And if you had trouble actually completing this program by yourself, then you should have noticed when

305
21:56.590 --> 22:02.080
we were walking through it, when I just broke down that big problem into smaller chunks, how much

306
22:02.080 --> 22:05.650
easier it became tackling each of the smaller things, right?

307
22:05.650 --> 22:08.380
Choosing a random number between 1 and 100.

308
22:08.380 --> 22:10.750
You can definitely do parts of this.

309
22:11.110 --> 22:16.160
And as you built up the game towards the end, you realized, uh, this was missing or that might be

310
22:16.160 --> 22:19.760
nice, then you could start adding more and more bits to it.

311
22:20.450 --> 22:25.790
But hopefully you've actually managed to build out your own version, and it's even better than what

312
22:25.790 --> 22:26.570
I've done.

313
22:26.570 --> 22:31.640
And if you're particularly proud of it, be sure to share it so that the rest of us can take a look

314
22:31.640 --> 22:33.500
and have a play with it as well.

315
22:33.590 --> 22:37.820
So I hope you enjoyed the project today and I'll see you tomorrow.