WEBVTT

0
00:00.330 --> 00:01.620
In the previous lesson,

1
00:01.650 --> 00:06.650
we managed to get our QuizBrain up and running and to start asking the user for

2
00:07.200 --> 00:08.033
their answer.

3
00:08.550 --> 00:13.550
But currently, there's no way for our program to continue to the next question

4
00:14.220 --> 00:17.250
once the user has typed an input. However,

5
00:17.250 --> 00:19.920
if we take a look at the final version of the quiz game,

6
00:20.280 --> 00:23.400
you can see once the user's typed an input, it

7
00:23.400 --> 00:28.400
then goes to the next question and shows them the question number 2

8
00:28.620 --> 00:31.320
and the question text for that second question.

9
00:32.190 --> 00:36.360
How can we create that functionality to work with our QuizBrain?

10
00:37.050 --> 00:37.290
Well,

11
00:37.290 --> 00:42.210
if we could create another method called still_has_questions

12
00:42.540 --> 00:46.800
well then inside our main.py we could probably create a while loop and

13
00:47.140 --> 00:48.420
the while loop checks

14
00:48.480 --> 00:52.950
if the quiz still has questions remaining.

15
00:53.550 --> 00:57.240
Well, then in that case, we're going to keep going to the next question.

16
00:57.870 --> 01:02.870
So how do we create this functionality and how do we create it inside the 

17
01:03.270 --> 01:07.680
QuizBrain? Your job is to create a new method here

18
01:08.040 --> 01:11.820
which is going to be called still_has_questions.

19
01:12.450 --> 01:16.440
And this is going to return a boolean, either true or false.

20
01:16.800 --> 01:18.240
And depending on that boolean,

21
01:18.360 --> 01:22.290
we can get our while loop to keep working and keep running and looping,

22
01:22.650 --> 01:25.020
or we're going to get the loop to stop

23
01:25.260 --> 01:28.050
once the quiz has run out of questions.

24
01:29.250 --> 01:33.000
Here's the behavior that you're looking for by the end of the challenge.

25
01:33.420 --> 01:38.280
The while loop should continue serving up the next question to the user until we

26
01:38.280 --> 01:40.050
reach the end of the quiz.

27
01:40.380 --> 01:45.380
Have a think about how the question number and the length of the question list

28
01:45.870 --> 01:50.190
relate to each other and see if you can complete this challenge.

29
01:53.820 --> 01:54.180
All right.

30
01:54.180 --> 01:59.180
So we know that we can get the length of our question list by using the Len

31
02:00.120 --> 02:05.120
function. Currently, in all the current version of the question bank,

32
02:05.700 --> 02:08.430
we have 12 questions in total.

33
02:08.880 --> 02:11.250
So the length is going to be 12.

34
02:11.850 --> 02:16.850
Now we want our loop to keep going until we've reached the number of questions

35
02:17.700 --> 02:18.570
in our list.

36
02:19.170 --> 02:24.170
What we could do is we could check to see if the self.question_number is

37
02:25.530 --> 02:30.530
less than the length of self.question_list. In that case, we'll return true,

38
02:32.430 --> 02:35.130
but otherwise we'll return false.

39
02:36.600 --> 02:40.980
Remember that this question number gets increased every time we show the user

40
02:40.980 --> 02:44.640
the next question. It starts out being zero

41
02:44.880 --> 02:46.920
and then it goes immediately to one.

42
02:47.370 --> 02:51.150
And then we get to the end of the next question function

43
02:51.540 --> 02:54.570
and we get to our while loop. So in our while loop,

44
02:54.600 --> 02:59.100
we can check to see if the quiz still has questions.

45
02:59.710 --> 03:04.210
And if this is true, then go to the next question. But if it's false,

46
03:04.240 --> 03:06.970
then exit the loop and we're at the end of the game.

47
03:08.050 --> 03:10.090
Back inside our QuizBrain

48
03:10.300 --> 03:15.300
we can actually simplify this method even more because we know that this is

49
03:16.020 --> 03:18.570
going to be evaluated by the computer

50
03:18.930 --> 03:23.010
and it's going to be either that true or false. If it is it's true

51
03:23.040 --> 03:26.130
then it goes into this block. And if it's false,

52
03:26.190 --> 03:27.900
then it goes into the else block.

53
03:28.410 --> 03:32.100
We can actually save ourselves all of this effort by 

54
03:32.130 --> 03:36.540
simply just returning this expression. Now,

55
03:36.540 --> 03:41.540
what it's going to do is, let's say that a = 5 and b =

56
03:45.030 --> 03:45.863
3.

57
03:46.260 --> 03:50.100
And if we were to return five is 

58
03:50.130 --> 03:51.540
greater than three,

59
03:51.870 --> 03:55.560
then this is basically the same as this expression

60
03:55.890 --> 04:00.150
which gets evaluated by the computer. And when this code runs,

61
04:00.180 --> 04:05.080
it's going to be either true or it's going to be false. So that

62
04:05.130 --> 04:07.860
that value is then going to be straight away

63
04:07.860 --> 04:12.180
returned by this method back into this while loop

64
04:12.240 --> 04:15.960
to see if we should continue going to the next question or not.

65
04:16.620 --> 04:21.510
So let's run this file and you can see it asks me the first question.

66
04:22.230 --> 04:24.480
And then it's going to go to the next question.

67
04:24.810 --> 04:29.810
And then it's going to basically keep going until it gets to the end of the list

68
04:31.230 --> 04:32.910
of questions and then it

69
04:32.970 --> 04:37.230
ends our entire program. In the next lesson

70
04:37.290 --> 04:42.150
we're going to figure out how we can check the answer that the user has inputted

71
04:42.150 --> 04:45.930
here and see if its actually the correct answer.