Build the league table
A sports app must show a league table, but different federations award different points. All results of one season are in matches.csv.
date: match dayhome,away: the two team nameshome_goals,away_goals: goals scored by each side
Task: the input is one line with three integers: win_points draw_points n. A win gives win_points, a draw gives draw_points, a loss gives 0. Rank the teams by points (highest first), then goal difference (goals for minus goals against, highest first), then goals scored (highest first), then team name alphabetically. Print the first n teams (or all if there are fewer), one per line, as RANK. Team POINTS GD GF separated by single spaces, where GD is printed with an explicit sign (+5, -3, +0). Ranks are simply 1, 2, 3 by position.
Files your program can read
date,home,away,home_goals,away_goals 2025-08-09,Madrid Royals,Milan Lions,1,2 2025-08-10,Madrid Royals,Lagos United,1,1 2025-08-11,Madrid Royals,Porto Anchors,3,1 2025-08-12,Madrid Royals,Rio Falcons,2,1 2025-08-16,Madrid Royals,Seoul Dragons,0,2 2025-08-17,Madrid Royals,Berlin Bears,0,1 2025-08-18,Madrid Royals,Lyon Owls,4,0 ...
Open them by name, for example open("matches.csv").
Sample test
Input
3 1 4
Expected output
1. Porto Anchors 26 +9 26 2. Berlin Bears 23 +1 20 3. Seoul Dragons 22 +3 18 4. Milan Lions 21 +3 17
Your answer is also checked against 4 hidden tests.
Need a hint?
Sort with a tuple key; put a minus sign in front of the numbers that must go highest first.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
