1 00:00:00,330 --> 00:00:01,620 In the previous lesson, 2 00:00:01,650 --> 00:00:06,650 we managed to get our QuizBrain up and running and to start asking the user for 3 00:00:07,200 --> 00:00:08,032 their answer. 4 00:00:08,550 --> 00:00:13,550 But currently, there's no way for our program to continue to the next question 5 00:00:14,220 --> 00:00:17,250 once the user has typed an input. However, 6 00:00:17,250 --> 00:00:19,920 if we take a look at the final version of the quiz game, 7 00:00:20,280 --> 00:00:23,400 you can see once the user's typed an input, it 8 00:00:23,400 --> 00:00:28,400 then goes to the next question and shows them the question number 2 9 00:00:28,620 --> 00:00:31,320 and the question text for that second question. 10 00:00:32,189 --> 00:00:36,360 How can we create that functionality to work with our QuizBrain? 11 00:00:37,050 --> 00:00:37,290 Well, 12 00:00:37,290 --> 00:00:42,210 if we could create another method called still_has_questions 13 00:00:42,540 --> 00:00:46,800 well then inside our main.py we could probably create a while loop and 14 00:00:47,140 --> 00:00:48,420 the while loop checks 15 00:00:48,480 --> 00:00:52,950 if the quiz still has questions remaining. 16 00:00:53,550 --> 00:00:57,240 Well, then in that case, we're going to keep going to the next question. 17 00:00:57,870 --> 00:01:02,870 So how do we create this functionality and how do we create it inside the 18 00:01:03,270 --> 00:01:07,680 QuizBrain? Your job is to create a new method here 19 00:01:08,040 --> 00:01:11,820 which is going to be called still_has_questions. 20 00:01:12,450 --> 00:01:16,440 And this is going to return a boolean, either true or false. 21 00:01:16,800 --> 00:01:18,240 And depending on that boolean, 22 00:01:18,360 --> 00:01:22,290 we can get our while loop to keep working and keep running and looping, 23 00:01:22,650 --> 00:01:25,020 or we're going to get the loop to stop 24 00:01:25,260 --> 00:01:28,050 once the quiz has run out of questions. 25 00:01:29,250 --> 00:01:33,000 Here's the behavior that you're looking for by the end of the challenge. 26 00:01:33,420 --> 00:01:38,280 The while loop should continue serving up the next question to the user until we 27 00:01:38,280 --> 00:01:40,050 reach the end of the quiz. 28 00:01:40,380 --> 00:01:45,380 Have a think about how the question number and the length of the question list 29 00:01:45,870 --> 00:01:50,190 relate to each other and see if you can complete this challenge. 30 00:01:53,820 --> 00:01:54,180 All right. 31 00:01:54,180 --> 00:01:59,180 So we know that we can get the length of our question list by using the Len 32 00:02:00,120 --> 00:02:05,120 function. Currently, in all the current version of the question bank, 33 00:02:05,700 --> 00:02:08,430 we have 12 questions in total. 34 00:02:08,880 --> 00:02:11,250 So the length is going to be 12. 35 00:02:11,850 --> 00:02:16,850 Now we want our loop to keep going until we've reached the number of questions 36 00:02:17,700 --> 00:02:18,570 in our list. 37 00:02:19,170 --> 00:02:24,170 What we could do is we could check to see if the self.question_number is 38 00:02:25,530 --> 00:02:30,530 less than the length of self.question_list. In that case, we'll return true, 39 00:02:32,430 --> 00:02:35,130 but otherwise we'll return false. 40 00:02:36,600 --> 00:02:40,980 Remember that this question number gets increased every time we show the user 41 00:02:40,980 --> 00:02:44,640 the next question. It starts out being zero 42 00:02:44,880 --> 00:02:46,920 and then it goes immediately to one. 43 00:02:47,370 --> 00:02:51,150 And then we get to the end of the next question function 44 00:02:51,540 --> 00:02:54,570 and we get to our while loop. So in our while loop, 45 00:02:54,600 --> 00:02:59,100 we can check to see if the quiz still has questions. 46 00:02:59,710 --> 00:03:04,210 And if this is true, then go to the next question. But if it's false, 47 00:03:04,240 --> 00:03:06,970 then exit the loop and we're at the end of the game. 48 00:03:08,050 --> 00:03:10,090 Back inside our QuizBrain 49 00:03:10,300 --> 00:03:15,300 we can actually simplify this method even more because we know that this is 50 00:03:16,020 --> 00:03:18,570 going to be evaluated by the computer 51 00:03:18,930 --> 00:03:23,010 and it's going to be either that true or false. If it is it's true 52 00:03:23,040 --> 00:03:26,130 then it goes into this block. And if it's false, 53 00:03:26,190 --> 00:03:27,900 then it goes into the else block. 54 00:03:28,410 --> 00:03:32,100 We can actually save ourselves all of this effort by 55 00:03:32,130 --> 00:03:36,540 simply just returning this expression. Now, 56 00:03:36,540 --> 00:03:41,540 what it's going to do is, let's say that a = 5 and b = 57 00:03:45,030 --> 00:03:45,863 3. 58 00:03:46,260 --> 00:03:50,100 And if we were to return five is 59 00:03:50,130 --> 00:03:51,540 greater than three, 60 00:03:51,870 --> 00:03:55,560 then this is basically the same as this expression 61 00:03:55,890 --> 00:04:00,150 which gets evaluated by the computer. And when this code runs, 62 00:04:00,180 --> 00:04:05,080 it's going to be either true or it's going to be false. So that 63 00:04:05,130 --> 00:04:07,860 that value is then going to be straight away 64 00:04:07,860 --> 00:04:12,180 returned by this method back into this while loop 65 00:04:12,240 --> 00:04:15,960 to see if we should continue going to the next question or not. 66 00:04:16,620 --> 00:04:21,510 So let's run this file and you can see it asks me the first question. 67 00:04:22,230 --> 00:04:24,480 And then it's going to go to the next question. 68 00:04:24,810 --> 00:04:29,810 And then it's going to basically keep going until it gets to the end of the list 69 00:04:31,230 --> 00:04:32,910 of questions and then it 70 00:04:32,970 --> 00:04:37,230 ends our entire program. In the next lesson 71 00:04:37,290 --> 00:04:42,150 we're going to figure out how we can check the answer that the user has inputted 72 00:04:42,150 --> 00:04:45,930 here and see if its actually the correct answer.