Now let's move on to Hint Number 10.
It says that if the game has not ended, ask the user if they want to draw another card.
If yes, then use the deal_card() function to add another card to the user_cards list,
if no, then the game has again ended. Over here in the if statement, we can add an else, because if
the game hasn't ended, as in they haven't gone over 21 or nobody's got a blackjack, then we're going
to ask the user if they want to get another card.
I'm going to use an input, and I'm going to ask the user to type 'y' to get another card,
otherwise type 'n' to pass.
And I'm going to save this input inside a variable which I'll call user_should_deal.
Now we can check to see if this variable is equal to 'y',
well, in that case, we're going to add another card to the user's card list by doing the same thing
that we did in the beginning, where we dealt two cards to each player by saying usercards.append(),
and inside the parentheses,
the thing that we want to append is the output from deal_card().
So just a quick check to make sure you've got all the parentheses there.
And then we're ready to address the else.
If they didn't type 'y', then that means they don't want another card.
Well then in this case, the game has again ended.
So we can say is_game_over = True.
Let's take a look at the next step.
How can we get our game to repeat itself?
So Hint Number 11 tells us that the score will need to be rechecked with every new card drawn, and
the checks in Hint 9 need to be repeated until the game ends.
Notice how we've got this, flag is_game_over, which is set to True whenever the game ends.
It starts off being False, and what this means is we can actually create a while loop, which basically
keeps on calculating the user_score,
and the computer_score, makes all of these checks, which are in Hint 9, and then repeats itself
until the game ends.
Let's go ahead and do that.
After all the initial setup, we're going to create a while loop, and the while loop is going to be
active until the game is over.
So we can say while not is_game_over, then go ahead and carry out all of these instructions.
So calculate the user_score,
calculate the computer_score,
check that nobody's gone over 21 and nobody's gotten a blackjack,
and if the user wants more cards, then they should,
if they don't, then the game is over.
So let's go ahead and run and test our code.
You can see that the first two cards we get are 10 and 5, which makes up a score of 15.
So 15 is kind of nowhere near 21,
so let's go ahead and type 'y' to get another card.
You can see that our while loop is active.
And it goes back to getting another card.
And we end up with 10, 5, and 10, which unfortunately means that we're over 21,
and so we lose.
But if I tried this and I typed 'n', then you can see the game ends immediately.
That worked perfectly.
So now let's go back and tackle the next part.
Hint number 12 says once the user is done, it's time to let the computer play.
The computer should keep drawing cards as long as it has a score less than 17.
So the while loop is responsible for dealing with when the user wants to keep drawing cards,
but once that's done, then we can tackle Hint Number 12, which is how does the computer actually play?
What is its strategy?
Well, we know that the computer has to keep drawing cards as long as it has a score of less than 17,
but of course, 0 which represents a blackjack, is also less than 17,
but we don't want it to draw a card if it has a blackjack.
We can represent this logic using a while loop, while the computer_score is not equal to 0, and
the computer_score is less than 17, then in this case we want to keep drawing cards.
We're going to take the computer's cards, and we're going to use the append to add a card by dealing
another card to the computer.
And then we're going to recalculate the computer_score so that it updates,
and this while loop is evaluated on the latest score.
So the computer_score is going to equal calculate_score() using the computer_cards,
and that means that the updated computer_score is equal to the return value from calculate_score().
Now one thing you'll notice here is that we've got a warning underline for the computer_score,
and when we hover underneath it it says the "Name 'computer_score' can be undefined."
So what does it mean here?
Well notice that we first define this variable computer_score inside this other while loop.
Now we're hoping that hopefully this happens first,
and by the time we reach Line 46, we already have a value for computer_score,
and this will happen in pretty much all cases.
But just in case there is a glitch, and there is no value for computer_score, or even in the case where
this entire while loop is skipped, then this computer_score will be equal to undefined.
It won't actually exist.
That variable won't have been created for us to check whether or not if it equals to 0, or if it's
greater or less than 17.
So how can we fix this?
Well, right up here where we've got our user_cards and computer_cards where we defined all of our empty
variables, we should go ahead and define this computer_score right here.
Now we can't set it to equal 0 by default, because that means blackjack in our game.
So let's set it to a number that we, when we test our code, will know for sure there is an issue.
Let's set it to a negative number.
So notice how as soon as I've got that variable defined somewhere outside of the while loop, this warning
now goes away and it will always have a value, even if it is a value that signifies there's something
wrong with our code.
And that will help us debug as well.
Now you'll notice that we've actually got a similar situation with the user_score.
The user_score is only defined inside this while loop, so it's created as a variable here and only
assigned as a variable here.
And in future if we want to use it, we also need to do the same thing.
So let's just also create a user_score and set it to -1 as well.
So now that we've completed Hint number 12, it's time to move on to the next video where we're going
to go through the final hints.