## Problem

Here are some basic facts about tennis scoring: A tennis match is made up of sets. A set is made up of games.

To win a set, a player has to win 6 games with a difference of 2 games. At 6-6, there is often a special tie-breaker. In some cases, players go on playing till one of them wins the set with a difference of two games.

Tennis matches can be either 3 sets or 5 sets. The player who wins a majority of sets wins the match (i.e., 2 out 3 sets or 3 out of 5 sets) The score of a match lists out the games in each set, with the overall winner’s score reported first for each set. Thus, if the score is 6-3, 5-7, 7-6 it means that the first player won the first set by 6 games to 3, lost the second one 5 games to 7 and won the third one 7 games to 6 (and hence won the overall match as well by 2 sets to 1).

You will read input from the keyboard (standard input) containing the results of several tennis matches. Each match’s score is recorded on a separate line with the following format:

Winner:Loser:Set-1-score,...,Set-k-score, where 2 ≤ k ≤ 5

For example, an input line of the form

```Halep:Wozniacki:3-6,6-3,6-3
```

indicates that Halep beat Wozniacki 3-6, 6-3, 6-3 in a best of 3 set match.

The input is terminated by a blank line.

You have to write a Python program that reads information about all the matches and compile the following statistics for each player:

1. Number of best-of-5 set matches won
2. Number of best-of-3 set matches won
3. Number of sets won
4. Number of games won
5. Number of sets lost
6. Number of games lost

You should print out to the screen (standard output) a summary in decreasing order of ranking, where the ranking is according to the criteria 1-6 in that order (compare item 1, if equal compare item 2, if equal compare item 3 etc, noting that for items 5 and 6 the comparison is reversed).

For instance, given the following data

```Federer:Nadal:2-6,6-7,7-6,6-3,6-1
Nadal:Federer:6-3,4-6,6-4,6-3
Federer:Nadal:6-0,7-6,6-7,6-3
Nadal:Federer:6-4,6-4
Federer:Nadal:2-6,6-2,6-0
Nadal:Federer:6-3,4-6,6-3,6-4
Federer:Nadal:7-6,4-6,7-6,2-6,6-2
Nadal:Federer:7-5,7-5
Halep:Wozniacki:3-6,6-3,6-3
```

your program should print out the following

```Federer 3 1 13 142 16 143
Nadal 2 2 16 143 13 142
Halep 0 1 2 15 1 12
Wozniacki 0 0 1 12 2 15
```

You can assume that there are no spaces around the punctuation marks “:”, “-” and “,”. Each player’s name will be spelled consistently and no two players have the same name.

## Solution

Download Python File:- Raw FileDownload (Please rename it to .py file once downloaded, for it to run)

If you are facing an issue in copy-pasting above code then just click on the Raw File and copy that code.

Categories: NPTEL solution

### 5 Comments

#### rohhiith · March 7, 2018 at 3:22 PM

It is getting runtime error.please check the code.
it is showing like this…
Test Case 1 Runtime Error
Input Expected Output Actual Output
Federer:Nadal:2-6,6-7,7-6,6-3,6-1
Nadal:Federer:6-3,4-6,6-4,6-3
Federer:Nadal:6-0,7-6,6-7,6-3
Nadal:Federer:6-4,6-4
Federer:Nadal:2-6,6-2,6-0
Nadal:Federer:6-3,4-6,6-3,6-4
Federer:Nadal:7-6,4-6,7-6,2-6,6-2
Nadal:Federer:7-5,7-5
Halep:Wozniacki:3-6,6-3,6-3

Federer 3 1 13 142 16 143\n
Nadal 2 2 16 143 13 142\n
Halep 0 1 2 15 1 12\n
Wozniacki 0 0 1 12 2 15\n
File “test.py”, line 65\n
elif int(score_pair_split[0])=(name2_5set_won + 1)):\n
^\n
SyntaxError: invalid syntax
Test Case 2 Runtime Error
Input Expected Output Actual Output
Halep:Raonic:2-6,6-7,7-6,6-3,6-1
Kerber:Raonic:6-3,4-6,6-4,6-3
Raonic:Wawrinka:6-0,7-6,6-7,6-3
Wawrinka:Raonic:6-4,6-4
Halep:Raonic:2-6,6-2,6-0
Wawrinka:Raonic:6-3,4-6,6-3,6-4
Raonic:Wawrinka:7-6,4-6,7-6,2-6,6-2
Wawrinka:Kerber:7-5,7-5
Halep:Kerber:3-6,6-3,6-3
Halep:Wawrinka:0-6,0-6,6-0,6-0,7-5
Kerber:Wawrinka:6-3,4-6,7-6,0-6,7-5

Halep 2 2 10 75 6 60\n
Raonic 2 0 11 122 16 139\n
Kerber 2 0 7 68 7 71\n
Wawrinka 1 2 14 133 13 128\n
File “test.py”, line 65\n
elif int(score_pair_split[0])=(name2_5set_won + 1)):\n
^\n
SyntaxError: invalid syntax

#### Mit Patel · March 7, 2018 at 4:06 PM

Please use raw code.

#### Sathish G · March 8, 2018 at 4:06 AM

Super dude….congrats to person who did this code…really good….

#### ramesh · March 14, 2018 at 11:09 AM

i had exams till today so i was not able to listen to classes
but with ur help i submitted my assignment
tqs a lot dude

#### Darshan · March 18, 2018 at 6:47 AM

Bro can u plz post week 6 and 7 quiz answers…. Plz post it soon