1 00:00:00,070 --> 00:00:02,170 All right, so let's go through the solution together. 2 00:00:02,680 --> 00:00:07,680 Now we know that the part that we need repeating is this part where we ask the 3 00:00:08,530 --> 00:00:11,890 user to guess a letter again and again 4 00:00:12,220 --> 00:00:16,090 until they filled out all the blanks in this display. 5 00:00:16,720 --> 00:00:21,720 The first step is to wrap a while loop around this block of code so we can 6 00:00:23,200 --> 00:00:28,200 select the entire block of code and you can either indent it individually or 7 00:00:28,510 --> 00:00:33,510 just select all of it and hit command and the right square bracket. 8 00:00:34,360 --> 00:00:37,600 And that will shift everything by one indentation level 9 00:00:37,870 --> 00:00:41,140 and that effectively puts it inside our while loop. 10 00:00:41,650 --> 00:00:43,960 So now we have to define our while loop. 11 00:00:44,290 --> 00:00:48,100 So while something is true or while something is false, 12 00:00:48,340 --> 00:00:53,170 repeat this code again and again. So what exactly is our condition? 13 00:00:54,130 --> 00:00:59,130 We know that we only want our loop to end once there are no more blanks 14 00:00:59,710 --> 00:01:02,830 contained inside the list called display. 15 00:01:03,550 --> 00:01:08,550 Why don't we create a variable which we'll call end_of_game and set that to 16 00:01:10,750 --> 00:01:11,320 false 17 00:01:11,320 --> 00:01:16,320 to begin with because it's not yet the end of game. And while it's not yet at the 18 00:01:17,290 --> 00:01:22,240 end of game, so while this is false. So you can either say while 19 00:01:22,240 --> 00:01:26,710 end of game is equal to false or alternatively 20 00:01:26,800 --> 00:01:31,800 and I think slightly easier to read is you could say while it's not at the end 21 00:01:32,440 --> 00:01:36,250 of the game, then repeat this continuously. Now, 22 00:01:36,280 --> 00:01:38,290 if we were to run our code right now 23 00:01:38,320 --> 00:01:41,530 it would actually loop on until forever. 24 00:01:41,620 --> 00:01:44,380 It would not stop because nowhere in our code, 25 00:01:44,590 --> 00:01:47,410 do we actually flip the switch and change this true. 26 00:01:48,100 --> 00:01:50,770 So when is it actually the end of the game? Well, 27 00:01:50,770 --> 00:01:53,650 it's when display has no more blanks. 28 00:01:54,640 --> 00:01:59,640 So why don't we check at the very end after we've printed the display to see if 29 00:02:01,630 --> 00:02:06,040 blanks are not in display. 30 00:02:07,180 --> 00:02:12,180 So remember this in key word comes from Python and it basically allows us to 31 00:02:12,760 --> 00:02:17,760 check to see if a particular element exists inside a particular list. So in this 32 00:02:18,730 --> 00:02:23,260 case, we're checking if curly exists in list and there it is. 33 00:02:23,260 --> 00:02:26,980 I can see it as one of the elements. So this is going to be true. 34 00:02:28,270 --> 00:02:30,220 Now, if blank 35 00:02:30,310 --> 00:02:34,150 in list is no longer true, well, 36 00:02:34,150 --> 00:02:38,110 that means that we've gotten rid of all the blanks and we replaced them with 37 00:02:38,110 --> 00:02:39,700 letters that the user has guessed. 38 00:02:40,090 --> 00:02:44,140 So now this is the condition for the user having won. 39 00:02:44,530 --> 00:02:47,710 So we can flip the end of game to true 40 00:02:48,340 --> 00:02:50,380 and this will mean that this is last time 41 00:02:50,500 --> 00:02:55,500 our while loop is going to run and we're going to print "You win." 42 00:02:57,580 --> 00:03:01,870 That's it, that's all we needed do. And if it's helpful, 43 00:03:01,930 --> 00:03:06,130 you can again, take this code, put it into Thonny and run through it 44 00:03:06,220 --> 00:03:10,060 using the debug step-by-step to see what it's doing. Now 45 00:03:10,120 --> 00:03:15,120 the important thing here is to realize that while statements require some sort 46 00:03:15,820 --> 00:03:19,090 of change to happen inside the while loop 47 00:03:19,390 --> 00:03:23,320 that changes the condition that the while loop is dependent upon 48 00:03:23,680 --> 00:03:28,240 and it means the code exits the while loop. So in this case, 49 00:03:28,270 --> 00:03:32,380 it's when there are no longer any more blanks inside the display list. 50 00:03:32,920 --> 00:03:34,330 But in later steps, 51 00:03:34,390 --> 00:03:37,600 we're going to change that so that when the users has run out of lives, 52 00:03:37,870 --> 00:03:41,620 then it's also going to be the end of the game and they will have lost. 53 00:03:42,880 --> 00:03:45,220 So take a moment, review this lesson, 54 00:03:45,370 --> 00:03:47,500 make sure you understand everything that's going on. 55 00:03:47,890 --> 00:03:51,520 Then head over to the next lesson and we'll tackle the next step.