ABOUT THE COURSE :
| Summary | |
|---|---|
| Course Type | Elective |
| Duration | 8 weeks |
| Category |
|
| Start Date | 22 Jan 2024 |
| End Date | 15 Mar 2024 |
| Exam Registration Ends | 16 Feb 2024 |
| Exam Date | 24 Mar 2024 IST |
Assignment Solutions : Week 5 Programming Assignment
For this assignment, you have to write a complete Python program. Paste your code in the window below.
- You may define additional auxiliary functions as needed.
- There are some public test cases and some (hidden) private test cases.
- "Compile and run" will evaluate your submission against the public test cases
- "Submit" will evaluate your submission against the hidden private test cases. There are 6 private test cases, with equal weightage. You will get feedback about which private test cases pass or fail, though you cannot see the actual test cases.
- Ignore warnings about "Presentation errors".
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
Jabeur:Swiatek:3-6,6-3,6-3
indicates that Jabeur beat Swiatek 3-6, 6-3, 6-3 in a best of 3 set match.
The input is terminated by a line consisting of the string "EOF".
You have to write a Python program that reads information about all the matches and compile the following statistics for each player:
- Number of best-of-5 set matches won
- Number of best-of-3 set matches won
- Number of sets won
- Number of games won
- Number of sets lost
- 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
Zverev:Alcaraz:2-6,6-7,7-6,6-3,6-1 Swiatek:Jabeur:6-4,6-4 Alcaraz:Zverev:6-3,6-3 Jabeur:Swiatek:1-6,7-5,6-2 Zverev:Alcaraz:6-0,7-6,6-3 Jabeur:Swiatek:2-6,6-2,6-0 Alcaraz:Zverev:6-3,4-6,6-3,6-4 Swiatek:Jabeur:6-1,3-6,7-5 Zverev:Alcaraz:7-6,4-6,7-6,2-6,6-2 Jabeur:Swiatek:6-4,1-6,6-3 Alcaraz:Zverev:7-5,7-5 Jabeur:Swiatek:3-6,6-3,6-3 EOF
your program should print out the following
Zverev 3 0 10 104 11 106 Alcaraz 1 2 11 106 10 104 Jabeur 0 4 9 76 8 74 Swiatek 0 2 8 74 9 76
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 : Copy & Pastedef orangecap(d):
scr = dict()
for msc in d:
for p in d[msc]:
if p in scr:
scr[p] += d[msc][p]
else:
scr[p] = d[msc][p]
pn=str()
tscr=0
for p in scr:
if scr[p] > tscr:
tscr = scr[p]
pn = p
return (pn, tscr)
def addpoly(p1, p2):
r = list()
for aq in range(len(p1)):
for j in range(len(p2)):
if p1[aq][1] == p2[j][1]:
r += [(p1[aq][0] + p2[j][0], p1[aq][1])]
for k in range(len(r)):
if r[k][1] == p1[aq][1]:
break
else:
r += [p1[aq]]
for j in range(len(p2)):
for k in range(len(r)):
if r[k][1] == p2[j][1]:
break
else:
r += [p2[j]]
r = [(c, e) for (c, e) in r if c != 0]
r.sort(key= lambda l : l[1], reverse=True)
return r
def multpoly(p1, p2):
rv = list()
for i in range(len(p1)):
for j in range(len(p2)):
rv = addpoly([(p1[i][0] * p2[j][0], p1[i][1] + p2[j][1])], rv)
return(rv)
CRITERIA TO GET A CERTIFICATE :
- Average assignment score = 25% of average of best 6 assignments out of the total 8 assignments given in the course. (All assignments in a particular week will be counted towards final scoring - quizzes and programming assignments).
- Exam score = 75% of the proctored certification exam score out of 100
- Final score = Average assignment score + Exam score
Follow Us