Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 difference between the number scored and the number conceded is calculated. The final table is based on the number on "win/loss" points, with the "difference" used to separate otherwise equal teams. This should all be familiar to anyone who follows a sport (which is good, because it is quite difficult to explain). Your program should read a file containing the results of matches, and display the final league table. The file contains one line per match, presented as CSV. For example, a file 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 file 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 file, probably easiest by scanning the result file 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 files 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 05/10/2021, 14:26 spec.md - Grip localhost:6419 2/3 The following output uses data from the 2021 Rugby Union Six Nations. As noted above, the rules have been simplified. 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 Sample Output: Command-line Argument 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 difference are the same (it does it on goals scored). tony@ceridwen ~/s/p/l/Task4$ ./league_table.py 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 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 tony@ceridwen ~/s/p/l/Task4$ cat teams.txt Croatia Czech Rep England 05/10/2021, 14:26 spec.md - Grip localhost:6419 3/3 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 Diff Pts 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago

Question

Define Management or What is Management?

Answered: 1 week ago