Introduction to Programming in Python, Aug-Dec 2014 Assignment 3 Due Wednesday, 8 October, 2014 ---------------------------------------------------------------------- Instructions ** IMPORTANT: Note new policy regarding naming of zip file ** 1. For each question, write a separate Python program with the filename indicated in the question. Zip your solutions into a single archive. Use your CMI username to name the zip file (e.g. "madhavan.zip") and submit the zip file via moodle. If you don't name your zip file or the enclosed Python file correctly, you risk losing marks. 2. If the question asks for a function, you *must* write a function in Python (i.e., def f(x): ... ) Ensure that the function you define has the name indicated in the question. Also ensure that your function returns the value asked for, rather than printing it. If you add code to your file to test your function, make sure you *remove* this code when you submit your solution. The Python file you submit should have *only* the function definition. ---------------------------------------------------------------------- NOTE: This assignment contains only one problem, and requires you to write a Python program that can be executed, not just a function. Filename: tennis.py 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 be given a text file 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: Williams:Sharapova:3-6,6-3,6-3 indicates that Williams beat Sharapova 3-6, 6-3, 6-3 in a best of 3 set match. 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 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 Djokovic:Nadal:2-6,6-7,7-6,6-3,6-1 Nadal:Djokovic:6-3,4-6,6-4,6-3 Djokovic:Nadal:6-0,7-6,6-7,6-3 Nadal:Djokovic:6-4,6-4 Djokovic:Nadal:2-6,6-2,6-0 Nadal:Djokovic:6-3,4-6,6-3,6-4 Djokovic:Nadal:7-6,4-6,7-6,2-6,6-2 Nadal:Djokovic:7-5,7-5 Williams:Sharapova:3-6,6-3,6-3 your program should print out the following Djokovic 3 1 13 142 16 143 Nadal 2 2 16 143 13 142 Williams 0 1 2 15 1 12 Sharapova 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. Your program should read its input from a text file "tennis.in" and write its output to a text file "tennis.out". ======================================================================