All right, guys, to get started, head over to the starting file in Step 1,
and we're going to tackle this project in five steps.
Now in Step 1 you'll see that there are three TODOs.
So I want you to go through each of them and complete them in the order they're listed one, two, and three.
Now in PyCharm there's a really helpful way to view all the TODOs in a particular file.
If you go to View, and then Tool Windows, and then scroll down to TODO, and you'll see all the TODOs
listed in order in the current file one, two and three.
Now the goal is to be able to achieve what the solution file does.
So without opening the solution file, which you need to double-click on,
you can also right-click on it and run the file without looking at it.
Now once you run it, you can see it's being run down here and it's printed a word,
so as we said in TODO Number 1, "Randomly choose a word from the word_list," up here, "and assign it
to a variable called chosen_word and then print it."
So there it is printed.
And then we ask the user to guess a letter, and that's TODO Number 2.
And then we have to make the guess lowercase.
So let's guess a letter, a,
and then finally we're going to check if the letter that the user guessed is one of the letters in the
chosen_word and print, "Right" if it is, or print, "Wrong" if it's not.
So it's going through each of the letters in this chosen_word, checking each one against the guessed
letter.
So it's not the first one, but it is the second one.
So A does in fact show up here.
And then it's also not in the last three letters.
So this is the goal of Step 1.
And I recommend you go through the TODOs, one by one using everything you've learned in the lessons
so far, you should be able to achieve this. If you get stuck,
there is a hint down here to tell you how to loop through lists,
but we did cover that at one point in the lessons.
So you could also go back to that previous lesson where we covered for loops and lists, to help
you as well.
So I'm going to go silent now and let you pause the video and complete this Step 1.
All right.
So now let's go through the solution.
I'm going to collapse everything just so that I have a bit more space to see each of my TODOs, and
alternatively, we can also just open up the TODO window.
So the first TODO is to randomly choose a word from the word_list.
So to do that we need to import the Random Module.
And then using the Random Module, you might remember that we saw that there was a function called random.choice().
And inside here we need to pass in a sequence.
And in this case, the sequence we want to pass in is our word_list.
So now that we've created a random word from that list, we need to assign it to a variable.
And in the TODO it says, "to assign it to a variable called chosen_word."
So we can just add an equal sign between those two things,
and now we have set it to this variable.
The final thing we need to do is simply just print the chosen_word.
And that's TODO Number 1 completed.
Now you might notice there is a yellow squiggly line under the import.
And that's because according to PEP 8 and Python style guidance, imports should always be at the very
top of the list.
But because we've got our TODOs as well, we had it down there.
But it would work in
both cases exactly the same.
So now let's tackle TODO Number 2, which is to ask the user to guess a letter and assign their answer
to a variable called guess.
So firstly, let's go ahead and figure out how to ask the user for a letter.
So we're going to use input.
And I'm simply just going to write, "Guess a letter..." colon, space.
And then we're going to assign this to a variable called guess.
And finally, we want to make this guess lowercase.
So we can simply write, .lower().
Now let's go ahead and print the value of guess and run our code, just to make sure that everything
works so far as we expect it to.
So instead of selecting solution, I'm going to select current file and hit Run.
So the first thing that prints is, baboon.
And this means that our TODO 1, was completed successfully because we randomly chose a word from the
word_list and then printed it out.
Now TODO 2 should ask the user to guess a letter and then go ahead and make it lowercase.
So we're printing it out just to make sure it works.
Let's say I guess the letter, but I type a capital A, now when I hit enter, hopefully this .lower()
function will turn it into lowercase,
and then it gets stored in this variable called guess, which gets printed out here.
Now the reason why we're turning it to lowercase is because the user might start off a letter in all caps,
or they might use lowercase,
but if we were to check against our words in the word_list, you'll notice that they're all in lowercase.
So if we make everything all the same casing, that makes our lives a lot easier down the line.
So we have now completed TODO 1 and TODO 2, and all that's left to do is TODO Number 3.
So what we want to do is we want to take this letter that the user guessed, A, check it against each of
the letters in the word that was randomly chosen, and see if it matches any of these letters.
So I would expect the first letter to be a wrong because A is not equal to B.
The second one I would expect it to print right.
And for the rest of the letters I would expect it to print wrong.
So if you remember, we can use a for loop to loop through things which are in a sequence.
And we can do that with lists.
But we can also do that with strings.
So we can basically use the same for-in loop that we learnt about previously, where we say 'for' a letter,
so this is a variable name that we give each of the letters in the chosen_word that we're going to loop
through.
You can call it anything you want.
And then we use 'in' to define what are we looping through.
So it's going to be the chosen_word.
And let's go ahead and just print letter just to make sure this is doing what we expect it to.
So let's finish off with the input and you can see what's happening here is it's looping through each
of the letters in this chosen_word, which in this case was aardvark,
and it's printing it one by one.
Now instead of printing the letter, we want to check to see if the letter is the same as the guess.
So if the letter that we're currently looking at in the chosen word A, is it the same as the guess
that the user inputted?
Well, if it is, in that case we're going to print, "Right,"
and if it's not, so in the case of else, making sure you've got it at the right indentation level, notice
how if and else are at the same starting line.
Then in this case we're going to print "Wrong."
So now let's rerun our code.
In this case the word that was chosen was camel.
And I'm still guessing the letter A.
Then it goes through this word, camel,
the first letter is c, c is not a.
So that's wrong.
Second letter is a,
so it's right.
And none of the other letters are a,
so it prints out wrong.
So this was what we wanted to achieve by the end of Step 1.
Did you manage to get it to work?
If not, don't worry.
Go back to your code, fix it.
And as long as you understand what's going on, and how the code works in your version, then that is
a success in my book.
Now, once you're ready, then head over to Step 2, and in the next video I'll describe the steps
in that section.