1
00:00:00,130 --> 00:00:03,730
Alright. So let's go through the solution together for this final step.

2
00:00:04,300 --> 00:00:06,970
The first step tells us to update the word list

3
00:00:07,060 --> 00:00:10,900
to use the word list from hangman_words.

4
00:00:11,470 --> 00:00:13,870
And it's actually got exactly the same name.

5
00:00:13,870 --> 00:00:16,540
So we don't even have to change it all that much.

6
00:00:17,110 --> 00:00:20,920
But what we do have to do is to make this error go away.

7
00:00:21,700 --> 00:00:24,790
If you haven't already, go ahead and delete this line in your code

8
00:00:25,180 --> 00:00:28,300
where you've got the word list using the previous three words.

9
00:00:28,870 --> 00:00:33,870
And instead, we're going to import the hangman_words.

10
00:00:35,860 --> 00:00:40,860
And now we should be able to tap into this word list by writing hangman_

11
00:00:41,470 --> 00:00:44,470
words.word_list.

12
00:00:44,980 --> 00:00:48,130
And this is the same way that we use the random module.

13
00:00:48,140 --> 00:00:52,750
So we imported the random module and then when we needed it, we simply said

14
00:00:52,810 --> 00:00:57,730
random.choice. So choice is a function inside the random module,

15
00:00:58,000 --> 00:00:59,800
and we can access it like

16
00:00:59,800 --> 00:01:04,800
so. Now if you want it to be a little bit simpler in terms of the code that you

17
00:01:05,050 --> 00:01:08,560
write and you don't want to rewrite hangman_words

18
00:01:08,560 --> 00:01:13,330
dot such and such, then instead of just importing hangman words,

19
00:01:13,360 --> 00:01:16,690
you can actually instead write from hangman

20
00:01:16,690 --> 00:01:20,200
words import the word_list.

21
00:01:20,680 --> 00:01:25,680
So now we can get rid of this part and we can just use the previous code that we

22
00:01:27,130 --> 00:01:28,300
had on line 7.

23
00:01:30,430 --> 00:01:33,460
Using that you can do the same thing for

24
00:01:33,460 --> 00:01:37,540
to-do number two. From the hangman_art

25
00:01:37,570 --> 00:01:42,570
you can import the stages and that will make this error go away. And for

26
00:01:43,810 --> 00:01:45,820
to-do number three,

27
00:01:45,880 --> 00:01:49,300
you can again say from hangman_art

28
00:01:49,330 --> 00:01:52,300
import the logo.

29
00:01:53,080 --> 00:01:56,080
And then we can just print the logo.

30
00:01:56,770 --> 00:01:58,990
Now notice how we're importing, um,

31
00:01:59,080 --> 00:02:03,460
two different things from the same file, hangman art.

32
00:02:03,640 --> 00:02:05,830
So if you didn't want to write it twice,

33
00:02:05,860 --> 00:02:10,600
you can in fact also just say from hangman_art import logo,

34
00:02:10,870 --> 00:02:15,640
stages, and this will import both the logo and the stages

35
00:02:15,730 --> 00:02:18,070
and you'll see that there's no errors down here.

36
00:02:19,810 --> 00:02:21,550
If that's at all confusing,

37
00:02:21,670 --> 00:02:25,810
be sure to read through the documentation that I've linked to in the course

38
00:02:25,810 --> 00:02:29,890
resources that talks all about Python modules and importing

39
00:02:30,220 --> 00:02:35,220
so you can familiarize yourself with this once more. Now on to-do four,

40
00:02:35,710 --> 00:02:39,400
we're going to check to see if the user has entered a letter that they've

41
00:02:39,400 --> 00:02:43,390
already guessed. And if it's a letter that they got right,

42
00:02:43,720 --> 00:02:47,650
then we're going to print the letter and let them know. To do this,

43
00:02:47,710 --> 00:02:49,930
we're going to check through the display,

44
00:02:50,140 --> 00:02:52,660
which is a list of letters that they've already guessed.

45
00:02:53,260 --> 00:02:58,260
And we're going to check to see if the guess is in the display list,

46
00:03:02,020 --> 00:03:05,260
well, in this case, they've already guessed that letter and it's a correct one.

47
00:03:05,590 --> 00:03:10,030
So we're just going to print out the feedback that, um,

48
00:03:10,060 --> 00:03:12,460
"You've already guessed

49
00:03:12,640 --> 00:03:15,220
and then we'll put in their guessed letter."

50
00:03:17,830 --> 00:03:21,070
Now, however, if the letter is not in the chosen word,

51
00:03:21,130 --> 00:03:24,670
then we're going to print out the letter and let them know that

52
00:03:26,770 --> 00:03:30,250
"You guessed this particular letter,

53
00:03:31,870 --> 00:03:34,120
that's not in the word.

54
00:03:36,340 --> 00:03:40,630
You lose a life." That's it.

55
00:03:40,720 --> 00:03:45,580
That's all we have to do and if we run our app as it is now,

56
00:03:45,910 --> 00:03:48,730
then you can see that the solution is stymied.

57
00:03:48,760 --> 00:03:51,700
So if we just check, um,

58
00:03:51,760 --> 00:03:55,090
against s then that's being added,

59
00:03:55,600 --> 00:03:57,700
and if we get a letter wrong,

60
00:03:58,510 --> 00:04:01,780
then we get told that's not in the word. You lose a life.

61
00:04:01,960 --> 00:04:04,030
And our hangman is being drawn out.

62
00:04:04,630 --> 00:04:08,830
And if we guess a correct letter that we've already guessed like s again,

63
00:04:09,250 --> 00:04:12,790
then it tells us that you've already guessed that letter.

64
00:04:13,510 --> 00:04:17,170
Now you can either choose to keep all of these print statements

65
00:04:17,200 --> 00:04:21,459
if it helps you understand what's going on, or alternatively at this stage,

66
00:04:21,620 --> 00:04:25,210
it might make things a little bit confusing and you can just comment it out.

67
00:04:26,050 --> 00:04:28,570
Have a look at the final version

68
00:04:28,600 --> 00:04:33,160
by going to the course resources where I'll link to the completed code that I've

69
00:04:33,160 --> 00:04:37,720
written here. And you can have a read through it and compare against yours.

70
00:04:38,200 --> 00:04:42,040
But essentially this is all there is to this project

71
00:04:42,130 --> 00:04:46,750
and you've now completed it in its entirety. Once you're happy with your code,

72
00:04:46,780 --> 00:04:50,680
go ahead and remove all the comments that are no longer useful like all the

73
00:04:50,680 --> 00:04:54,190
to-dos and the testing code

74
00:04:54,220 --> 00:04:57,760
because if you wanna play the game for real, then that's just cheating.

75
00:04:58,240 --> 00:05:00,790
If you want to leave in some of the comments that lets you know

76
00:05:00,790 --> 00:05:04,030
what each part of code does so that when you come back to it,

77
00:05:04,330 --> 00:05:07,360
it's easier to understand, then feel free to do that.

78
00:05:07,930 --> 00:05:12,700
But the final thing that I wanted to show you is what if you wanted it to be

79
00:05:12,700 --> 00:05:16,450
able to clear the screen after every answer,

80
00:05:16,870 --> 00:05:20,650
because you can see that some point you have to keep scrolling and it gets a

81
00:05:20,650 --> 00:05:23,770
little bit confusing as to which stage you're in.

82
00:05:24,250 --> 00:05:29,250
So one of the things that you can do is you can tap into the replit module

83
00:05:30,940 --> 00:05:33,490
and you can import a function called clear.

84
00:05:34,090 --> 00:05:36,730
Once you've imported this clear function,

85
00:05:37,570 --> 00:05:42,570
then you can go ahead and add it just after the user has made their guess.

86
00:05:43,120 --> 00:05:46,030
So you can call it just as you would any other function

87
00:05:46,060 --> 00:05:50,710
now that you've imported it into this file. And when you run the code now,

88
00:05:52,660 --> 00:05:56,890
you can see that after every guess, it's going to clear the screen.

89
00:05:57,290 --> 00:06:00,140
So guess a letter, let's guess a different letter.

90
00:06:01,140 --> 00:06:05,510
Now that means we don't have this backlog of previous guesses and we can

91
00:06:05,510 --> 00:06:09,920
actually see what's going on at each stage. In the course resources,

92
00:06:09,920 --> 00:06:14,920
you'll also find a link to the final completed code on the day seven hangman final,

93
00:06:15,890 --> 00:06:20,270
and feel free to modify this code to, your heart's content, make it

94
00:06:20,270 --> 00:06:24,020
do whatever it is that you want to do and push the boundaries of your

95
00:06:24,020 --> 00:06:24,920
programming skills

96
00:06:25,340 --> 00:06:29,660
if you want to. Well done for getting this far and well done for tackling this

97
00:06:29,660 --> 00:06:32,720
challenge. Rest easy, and I'll see you tomorrow.

