Challenge: Maintain Total Points

Here is a coding challenge based on the concepts covered in this chapter.

We'll cover the following

Problem statement #

Write a function addPoints() that increases the total points of two football (soccer) teams according to the result of a game.
The first two parameters (goals1, goals2) of this function are the goals that each team has scored. The other two parameters (points1, points2) are the points of each team before the game. This function should adjust the points of the teams according to the goals that they have scored, increasing the points by one each time a goal is scored. As a reminder:

  • the winner takes 3 points.
  • the loser takes no point.
  • in the event of a draw, both teams get 1 point each.

Additionally, the function should indicate which team has been the winner:

  • 1 if the first team has won.
  • 2 if the second team has won.
  • 0 if the game has ended in a draw.

Start with the following program and fill in the four in, out, do and unittest blocks of the function appropriately. Do not remove the assert checks in main(); they demonstrate how this function is expected to work.

Challenge #

This problem is designed for you to practice, so try to solve it on your own first. If you get stuck, you can always refer to the explanation and solution provided in the next lesson. Good luck!

Get hands-on with 1200+ tech skills courses.