Alright. So let's go through the solution together for this final step.
The first step tells us to update the word list
to use the word list from hangman_words.
And it's actually got exactly the same name.
So we don't even have to change it all that much.
But what we do have to do is to make this error go away.
If you haven't already, go ahead and delete this line in your code
where you've got the word list using the previous three words.
And instead, we're going to import the hangman_words.
And now we should be able to tap into this word list by writing hangman_
words.word_list.
And this is the same way that we use the random module.
So we imported the random module and then when we needed it, we simply said
random.choice. So choice is a function inside the random module,
and we can access it like
so. Now if you want it to be a little bit simpler in terms of the code that you
write and you don't want to rewrite hangman_words
dot such and such, then instead of just importing hangman words,
you can actually instead write from hangman
words import the word_list.
So now we can get rid of this part and we can just use the previous code that we
had on line 7.
Using that you can do the same thing for
to-do number two. From the hangman_art
you can import the stages and that will make this error go away. And for
to-do number three,
you can again say from hangman_art
import the logo.
And then we can just print the logo.
Now notice how we're importing, um,
two different things from the same file, hangman art.
So if you didn't want to write it twice,
you can in fact also just say from hangman_art import logo,
stages, and this will import both the logo and the stages
and you'll see that there's no errors down here.
If that's at all confusing,
be sure to read through the documentation that I've linked to in the course
resources that talks all about Python modules and importing
so you can familiarize yourself with this once more. Now on to-do four,
we're going to check to see if the user has entered a letter that they've
already guessed. And if it's a letter that they got right,
then we're going to print the letter and let them know. To do this,
we're going to check through the display,
which is a list of letters that they've already guessed.
And we're going to check to see if the guess is in the display list,
well, in this case, they've already guessed that letter and it's a correct one.
So we're just going to print out the feedback that, um,
"You've already guessed
and then we'll put in their guessed letter."
Now, however, if the letter is not in the chosen word,
then we're going to print out the letter and let them know that
"You guessed this particular letter,
that's not in the word.
You lose a life." That's it.
That's all we have to do and if we run our app as it is now,
then you can see that the solution is stymied.
So if we just check, um,
against s then that's being added,
and if we get a letter wrong,
then we get told that's not in the word. You lose a life.
And our hangman is being drawn out.
And if we guess a correct letter that we've already guessed like s again,
then it tells us that you've already guessed that letter.
Now you can either choose to keep all of these print statements
if it helps you understand what's going on, or alternatively at this stage,
it might make things a little bit confusing and you can just comment it out.
Have a look at the final version
by going to the course resources where I'll link to the completed code that I've
written here. And you can have a read through it and compare against yours.
But essentially this is all there is to this project
and you've now completed it in its entirety. Once you're happy with your code,
go ahead and remove all the comments that are no longer useful like all the
to-dos and the testing code
because if you wanna play the game for real, then that's just cheating.
If you want to leave in some of the comments that lets you know
what each part of code does so that when you come back to it,
it's easier to understand, then feel free to do that.
But the final thing that I wanted to show you is what if you wanted it to be
able to clear the screen after every answer,
because you can see that some point you have to keep scrolling and it gets a
little bit confusing as to which stage you're in.
So one of the things that you can do is you can tap into the replit module
and you can import a function called clear.
Once you've imported this clear function,
then you can go ahead and add it just after the user has made their guess.
So you can call it just as you would any other function
now that you've imported it into this file. And when you run the code now,
you can see that after every guess, it's going to clear the screen.
So guess a letter, let's guess a different letter.
Now that means we don't have this backlog of previous guesses and we can
actually see what's going on at each stage. In the course resources,
you'll also find a link to the final completed code on the day seven hangman final,
and feel free to modify this code to, your heart's content, make it
do whatever it is that you want to do and push the boundaries of your
programming skills
if you want to. Well done for getting this far and well done for tackling this
challenge. Rest easy, and I'll see you tomorrow.