Question: Introduction to Programming Assignment: Task 4 You should only attempt this task if you have completed the other partsof the assignment easily and want an
Introduction to Programming
Assignment: Task 4
You should only attempt this task if you have completed the other partsof the assignment easily and want an extra challenge. It is possible to pass the module very well withoutattempting this nal task!
The Problem
In this task you will develop a program that will process the results of some sporting event where four teams are competing in a small league. It could be a group at an event such as the recent football Euros, but you are welcome to base it on any similar sport (a group at the rugby world cup, the netball world cup, ice hockey ...).
Whatever sport, we will assume that the rules are as follows: Teams play each other once.
Teams are awarded three points for winning, one for a draw, and none for losing.
Teams score goals (points) in each game, and the dierence between the number scored and the number conceded is calculated.
The nal table is based on the number on "win/loss" points, with the "dierence" used to separate otherwise equal teams.
This should all be familiar to anyone who follows a sport (which is good, because it is quite dicult to explain). Your program should read a le containing the results of matches, and display the nal league table.
The le contains one line per match, presented as CSV. For example, a le from this year's Rugby Union Six Nations would contain lines such as:
Italy,10,
Ireland,48
Scotland,24,
Wales,25
Wales,40,
England,24
To keep things simple, you may want to provide a separate le that contains the names of the competing teams, one per line:
England Ireland Wales Scotland Italy
(It is obviously possible to program this task without the second le, probably easiest by scanning the result le twice. This is actually what the version generating the sample output below is doing.)
Implementation
Implement a solution using classes. There are a bunch of ways to do this. The solution generating the output below uses just one class to represent the team in the league, but you could use an additional class to represent a result. Arguably the league itself should be a class. Your call.
It is safe to assume that the les exist, and that there is complete and consistent data present.
Note: Rugby fans will know that there are additional rules for bonus points in the Six Nations. These have not been implemented below (so the same code would work with other sports). You are welcome to implement them should you want to make a more realistic solution.
Examples
The following output uses data from the 2021 Rugby Union Six Nations. As noted above, the rules have been simplied. This version has an optional command-line parameter providing the name of the competition.
Teams File
England
France
Ireland
Italy
Scotland
Wales
Results File
Italy,10,France,50
England,6,Scotland,11
Wales,21,Ireland,16
England,41,Italy,18
Scotland,24,Wales,25
Ireland,13,France,15
Italy,10,Ireland,48
Wales,40,England,24
Italy,7,Wales,48
England,23,France,20
Scotland,24,Ireland,27
Scotland,52,Italy,10
Ireland,32,England,18
France,32,Wales,30
France,23,Scotland,27
Sample Output: No Command-line Argument
tony@ceridwen ~/s/p/l/Task4$ ./league_table.py "Six Nations 2021"
| P | W | D | L | F A | Diff | Pts | |
| Wales | 5 | 4 | 0 | 1 | 164 103 | 61 | 12 |
| Ireland | 5 | 3 | 0 | 2 | 136 88 | 48 | 9 |
| Scotland | 5 | 3 | 0 | 2 | 138 91 | 47 | 9 |
| France | 5 | 3 | 0 | 2 | 140 103 | 37 | 9 |
| England | 5 | 2 | 0 | 3 | 112 121 | -9 | 6 |
Italy 5 0 0 5 55 239 -184 0
Sample Output: Command-line Argument
tony@ceridwen ~/s/p/l/Task4$ ./league_table.py "Six Nations 2021"
Six Nations 2021
================
| P | W | D | L | F A | Diff | Pts | |
| Wales | 5 | 4 | 0 | 1 | 164 103 | 61 | 12 |
| Ireland | 5 | 3 | 0 | 2 | 136 88 | 48 | 9 |
| Scotland | 5 | 3 | 0 | 2 | 138 91 | 47 | 9 |
| France | 5 | 3 | 0 | 2 | 140 103 | 37 | 9 |
| England | 5 | 2 | 0 | 3 | 112 121 | -9 | 6 |
Italy 5 0 0 5 55 239 -184 0
Finally, here is the same code processing the results from England's group at the 2020 Euros. Notice that it works out how teams are ordered when points and goal dierence are the same (it does it on goals scored).
tony@ceridwen ~/s/p/l/Task4$ cat teams.txt
Croatia
Czech Rep
England
Scotland
tony@ceridwen ~/s/p/l/Task4$ cat results.txt
England,1,Croatia,0
Scotland,0,Czech Rep,2
Croatia,1,Czech Rep,1
England,0,Scotland,0
Croatia,3,Scotland,1
Czech Rep,0,England,1
tony@ceridwen ~/s/p/l/Task4$ ./league_table.py "Euro 2020 Group D"
Euro 2020 Group D
=================
P W D L F A DiffPts
| England | 3 | 2 | 1 | 0 | 2 | 0 | 2 | 7 |
| Croatia | 3 | 1 | 1 | 1 | 4 | 3 | 1 | 4 |
| Czech Rep | 3 | 1 | 1 | 1 | 3 | 2 | 1 | 4 |
| Scotland | 3 | 0 | 1 | 2 | 1 | 5 | -4 | 1 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
