Today, we continued the matrix (2-dimensional array) in Python in Computer Science 1. We added an additional 88 data points to the existing 44 we started with. This brings the total number of points to 132.

See the post entitled “Starting a Matrix in Python” for the first part of the program code.

Now, we are going to remove lines 48 through 58 of the code to continue entering data.

teams[0][4] = 6 teams[1][4] = 0 teams[2][4] = 2 teams[3][4] = 6 teams[4][4] = 6 teams[5][4] = 4 teams[6][4] = 10 teams[7][4] = 6 teams[8][4] = 6 teams[9][4] = 4 teams[10][4] = 0 teams[0][5] = 210 teams[1][5] = 105 teams[2][5] = 132 teams[3][5] = 183 teams[4][5] = 212 teams[5][5] = 184 teams[6][5] = 220 teams[7][5] = 156 teams[8][5] = 160 teams[9][5] = 164 teams[10][5] = 0

Here, we are adding the scores for each team from the first league meet of the 2017/2018 season as new columns 4 and 5 to the array. You can see these are being entered as integers as we will be doing some math with them later.

teams[0][6] = 6 teams[1][6] = 4 teams[2][6] = 4 teams[3][6] = 10 teams[4][6] = 2 teams[5][6] = 0 teams[6][6] = 6 teams[7][6] = 4 teams[8][6] = 4 teams[9][6] = 0 teams[10][6] = 0 teams[0][7] = 257 teams[1][7] = 257 teams[2][7] = 220 teams[3][7] = 314 teams[4][7] = 205 teams[5][7] = 0 teams[6][7] = 238 teams[7][7] = 277 teams[8][7] = 224 teams[9][7] = 0 teams[10][7] = 0

We are now adding the scores from each team from the second league meet of the 2017/2018 season as new columns 6 and 7 to the array.

teams[0][8] = 6 teams[1][8] = 6 teams[2][8] = 6 teams[3][8] = 6 teams[4][8] = 4 teams[5][8] = 6 teams[6][8] = 6 teams[7][8] = 6 teams[8][8] = 0 teams[9][8] = 2 teams[10][8] = 6 teams[0][9] = 188 teams[1][9] = 168 teams[2][9] = 156 teams[3][9] = 218 teams[4][9] = 160 teams[5][9] = 202 teams[6][9] = 244 teams[7][9] = 184 teams[8][9] = 156 teams[9][9] = 152 teams[10][9] = 140

We are now adding the scores from each teams from the third league meet of the 2017/2018 season as new columns 8 and 9 to the array.

teams[0][10] = 5 teams[1][10] = 8 teams[2][10] = 3 teams[3][10] = 7 teams[4][10] = 2 teams[5][10] = 6 teams[6][10] = 6 teams[7][10] = 3 teams[8][10] = 2 teams[9][10] = 0 teams[10][10] = 8 teams[0][11] = 400 teams[1][11] = 312 teams[2][11] = 363 teams[3][11] = 400 teams[4][11] = 346 teams[5][11] = 332 teams[6][11] = 330 teams[7][11] = 413 teams[8][11] = 289 teams[9][11] = 0 teams[10][11] = 267

We now add the results from the league tournament final qualifying rounds of the 2017/2018 season as new columns 10 and 11 to the array.

Now, what we need to do is calculate the total qualifying points, which determines placement. This is done by calculating the sum of all qualifying points for each team individually. This was stored in columns 4, 6, 8, & 10 in the array.

In the event of a tie in the qualifying points, we take the sum of the 3 highest ranking points scores for each team. The team with the higher ranking points wins the tie-break. The ranking points are stored in columns 5, 7, 9, & 11 in the array.

Calculating the qualifying points for each team is somewhat easy and can be done using simple arithmetic functions.

teams[0][12] = teams[0][4] + teams[0][6] + teams[0][8] + teams [0][10] teams[1][12] = teams[1][4] + teams[1][6] + teams[1][8] + teams [1][10] teams[2][12] = teams[2][4] + teams[2][6] + teams[2][8] + teams [2][10] teams[3][12] = teams[3][4] + teams[3][6] + teams[3][8] + teams [3][10] teams[4][12] = teams[4][4] + teams[4][6] + teams[4][8] + teams [4][10] teams[5][12] = teams[5][4] + teams[5][6] + teams[5][8] + teams [5][10] teams[6][12] = teams[6][4] + teams[6][6] + teams[6][8] + teams [6][10] teams[7][12] = teams[7][4] + teams[7][6] + teams[7][8] + teams [7][10] teams[8][12] = teams[8][4] + teams[8][6] + teams[8][8] + teams [8][10] teams[9][12] = teams[9][4] + teams[9][6] + teams[9][8] + teams [9][10] teams[10][12] = teams[10][4] + teams[10][6] + teams[10][8] + teams [10][10]

As you can see, we have added column 12 to the array and it holds the sum of columns 4, 6, 8, & 10 for the given row. This is the total qualifying points.

We can add a “test-print” using the following:

print(teams[0][0] + " - " + str(teams[0][12])) print(teams[1][0] + " - " + str(teams[1][12])) print(teams[2][0] + " - " + str(teams[2][12])) print(teams[3][0] + " - " + str(teams[3][12])) print(teams[4][0] + " - " + str(teams[4][12])) print(teams[5][0] + " - " + str(teams[5][12])) print(teams[6][0] + " - " + str(teams[6][12])) print(teams[7][0] + " - " + str(teams[7][12])) print(teams[8][0] + " - " + str(teams[8][12])) print(teams[9][0] + " - " + str(teams[9][12])) print(teams[10][0] + " - " + str(teams[10][12]))

You can see that we are displaying the team number from column 0, concatenated with a space a hyphen and space, which is then concatenated with the values from column 12 cast as a string.

The output looks similar to the following:

Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux 127 - 23 5443 - 18 9402 - 15 9403 - 29 10143 - 14 11085 - 16 11242 - 28 12645 - 19 12650 - 12 12992 - 6 13915 - 14

Next class, we will take a look at how to calculate the tie-breaker. As you can see, it will be needed as there is a tie between FTC 10143 and FTC 13915.