Initializing the score

In order to have a score, we are going to create a variable for each player that begins at the default score, zero. As this is a global variable, like the other integers, it will change as the game loop runs. For now, we just need to have placeholders for each player. So, starting on line 46, add these lines of code to your game:

  # initialize score
  player1_score = 0
  player2_score = 0

We have now created all of the global variables that we need to write code that is easier to understand. Remember, these are called global variables because they can be used throughout the entire code file. Save your file. Then, compare your code with the completed code in this screenshot:

Get Python Projects for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.