Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Week 5 Programming Assignment: (Https://swayam - Gov.in)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

reviewer4@nptel.iitm.ac.in 

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming, Data Structures And Algorithms

Using Python (course)

Announcements (announcements)

About the Course (https://swayam.gov.in/nd1_noc19_cs40/preview) Ask a Question (forum)

Progress (student/home) Mentor (student/mentor)

Week 5 Programming Assignment


Course Due on 2019-09-06, 23:59 IST
outline
For this assignment, you have to write a complete Python program. Paste your
code in the window below.
How to access
the portal You may define additional auxiliary functions as needed.
There are some public test cases and some (hidden) private test cases.
Week 1: "Compile and run" will evaluate your submission against the public test
Introduction cases
"Submit" will evaluate your submission against the hidden private test
Week 1 Quiz 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
Week 2: Basics
see the actual test cases.
of Python Ignore warnings about "Presentation errors".

Week 2 Quiz
Here are some basic facts about tennis scoring: A tennis match is made up of
Week 2 sets. A set is made up of games.
Programming To win a set, a player has to win 6 games with a difference of 2 games. At 6-6,
Assignment
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.
Week 3: Lists,
inductive Tennis matches can be either 3 sets or 5 sets. The player who wins a majority
function of sets wins the match (i.e., 2 out 3 sets or 3 out of 5 sets) The score of a match
definitions, lists out the games in each set, with the overall winner's score reported first for
sorting 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
Week 3 one 7 games to 6 (and hence won the overall match as well by 2 sets to 1).
Programming
You will read input from the keyboard (standard input) containing the results of
Assignment
several tennis matches. Each match's score is recorded on a separate line with
th f ll i f t

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 1/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

the following format:


Week 4: Sorting,
Tuples, Winner:Loser:Set-1-score,...,Set-k-score, where 2 ≤ k ≤ 5
Dictionaries,
For example, an input line of the form
Passing
Functions, List
Halep:Wozniacki:3-6,6-3,6-3
Comprehension

Week 4 Quiz 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.
Week 4
You have to write a Python program that reads information about all the
Programming
Assignment
matches and compile the following statistics for each player:
1. Number of best-of-5 set matches won
Week 5: 2. Number of best-of-3 set matches won
Exception 3. Number of sets won
handling, 4. Number of games won
input/output, file 5. Number of sets lost
handling, string 6. Number of games lost
processing
You should print out to the screen (standard output) a summary in decreasing
Week 5 order of ranking, where the ranking is according to the criteria 1-6 in that order
Programming (compare item 1, if equal compare item 2, if equal compare item 3 etc, noting
Assignment that for items 5 and 6 the comparison is reversed).
For instance, given the following data
Week 5
Programming
Assignment
Federer:Nadal:2-6,6-7,7-6,6-3,6-1
Nadal:Federer:6-3,4-6,6-4,6-3
(/noc19_cs40/progassignment?
name=95) Federer:Nadal:6-0,7-6,6-7,6-3
Nadal:Federer:6-4,6-4
Week 6: Federer:Nadal:2-6,6-2,6-0
Backtracking, Nadal:Federer:6-3,4-6,6-3,6-4
scope, data Federer:Nadal:7-6,4-6,7-6,2-6,6-2
structures; Nadal:Federer:7-5,7-5
stacks, queues Halep:Wozniacki:3-6,6-3,6-3
and heaps

Week 6 Quiz
your program should print out the following

Federer 3 1 13 142 16 143


Week 7:
Nadal 2 2 16 143 13 142
Classes, objects
Halep 0 1 2 15 1 12
and user
Wozniacki 0 0 1 12 2 15
defined
datatypes
You can assume that there are no spaces around the punctuation marks ":", "-"
Week 7 Quiz and ",". Each player's name will be spelled consistently and no two players have
the same name.
Week 8:
Dynamic Sample Test Cases
programming, Input Output
wrap-up

Week 8
Programming
Assignment

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 2/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

Download Federer:Djokovic:2-6,6-7,7-
videos 6,6-3,6-1
Djokovic:Federer:6-3,4-6,6-
Text Transcripts 4,6-3
Federer:Djokovic:6-0,7-6,6-
Online 7,6-3 Federer 3 1 13 142
Programming Djokovic:Federer:6-4,6-4 16 143
Test - Sample Test Federer:Djokovic:2-6,6-2,6- Djokovic 2 2 16 143
Case 1 0 13 142
Online Djokovic:Federer:6-3,4-6,6- Halep 0 1 2 15 1 12
Programming 3,6-4 Barty 0 0 1 12 2 15
Test 1, 26 Sep Federer:Djokovic:7-6,4-6,7-
2019, 09:30- 6,2-6,6-2
11:30 Djokovic:Federer:7-5,7-5
Halep:Barty:3-6,6-3,6-3
Online
Programming
Test 2, 26 Sep Halep:Medvedev:2-6,6-7,7-6,
2019, 20:00-
6-3,6-1
22:00
Williams:Medvedev:6-3,4-6,6
-4,6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Halep 2 2 10 75 6 6
Thiem:Medvedev:6-4,6-4
0
Halep:Medvedev:2-6,6-2,6-0
Medvedev 2 0 11 122
Thiem:Medvedev:6-3,4-6,6-3,
Test 16 139
6-4
Case 2 Williams 2 0 7 68 7
Medvedev:Thiem:7-6,4-6,7-6,
71
2-6,6-2
Thiem 1 2 14 133 13
Thiem:Williams:7-5,7-5
128
Halep:Williams:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Williams:Thiem:6-3,4-6,7-6,
0-6,7-5

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 3/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

Djokovic:Zverev:2-6,6-7,7-
6,6-3,6-1
Zverev:Djokovic:6-3,4-6,6-
4,6-3
Djokovic:Zverev:6-0,7-6,6-
7,6-3
Zverev:Djokovic:6-4,6-4
Djokovic:Zverev:2-6,6-2,6-0
Zverev:Djokovic:6-3,4-6,6-
3,6-4
Djokovic:Zverev:7-6,4-6,7-
6,2-6,6-2
Williams 3 2 16 160
Zverev:Djokovic:7-5,7-5
16 146
Williams:Muguruza:3-6,6-3,6
Muguruza 3 1 16 146
-3
Test 16 160
Muguruza:Williams:6-4,6-4
Case 3 Djokovic 3 1 13 142
Williams:Muguruza:2-6,6-2,6
16 143
-0
Zverev 2 2 16 143 1
Muguruza:Williams:6-3,4-6,6
3 142
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 4/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Barty:Medvedev:6-3,4-6,6-4,
6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4
Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Barty:7-5,7-5
Halep:Barty:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
Halep 4 4 20 150 12
0,7-5
120
Barty:Thiem:6-3,4-6,7-6,0-
Medvedev 4 0 22 244
6,7-5
Test 32 278
Halep:Medvedev:2-6,6-7,7-6,
Case 4 Barty 4 0 14 136 14
6-3,6-1
142
Barty:Medvedev:6-3,4-6,6-4,
Thiem 2 4 28 266 26
6-3
256
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4
Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Barty:7-5,7-5
Halep:Barty:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Barty:Thiem:6-3,4-6,7-6,0-
6,7-5

Test
Djokovic:Zverev:2-6,6-7,7- Halep 4 4 20 150 12
Case 5
6,6-3,6-1 120
Zverev:Djokovic:6-3,4-6,6- Medvedev 4 0 22 244
4,6-3 32 278
Djokovic:Zverev:6-0,7-6,6- Kerber 4 0 14 136 1
7,6-3 4 142
Zverev:Djokovic:6-4,6-4 Williams 3 2 16 160
Djokovic:Zverev:2-6,6-2,6-0 16 146
Zverev:Djokovic:6-3,4-6,6- Muguruza 3 1 16 146
3,6-4 16 160
Djokovic:Zverev:7-6,4-6,7- Djokovic 3 1 13 142
6,2-6,6-2 16 143
Zverev:Djokovic:7-5,7-5 Thiem 2 4 28 266 26
Williams:Muguruza:3-6,6-3,6 256
-3

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 5/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

Muguruza:Williams:6-4,6-4 Zverev 2 2 16 143 1


Williams:Muguruza:2-6,6-2,6 3 142
-0
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Kerber:Medvedev:6-3,4-6,6-
4,6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4
Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Kerber:7-5,7-5
Halep:Kerber:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Kerber:Thiem:6-3,4-6,7-6,0-
6,7-5
Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Kerber:Medvedev:6-3,4-6,6-
4,6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4
Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Kerber:7-5,7-5
Halep:Kerber:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Kerber:Thiem:6-3,4-6,7-6,0-
6,7-5

Test

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 6/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

Case 6 Djokovic:Zverev:2-6,6-7,7- Halep 8 8 40 300 24


6,6-3,6-1 240
Zverev:Djokovic:6-3,4-6,6- Medvedev 8 0 44 488
4,6-3 64 556
Djokovic:Zverev:6-0,7-6,6- Barty 8 0 28 272 28
7,6-3 284
Zverev:Djokovic:6-4,6-4 Williams 6 4 32 320
Djokovic:Zverev:2-6,6-2,6-0 32 292
Zverev:Djokovic:6-3,4-6,6- Muguruza 6 2 32 292
3,6-4 32 320
Djokovic:Zverev:7-6,4-6,7- Djokovic 6 2 26 284
6,2-6,6-2 32 286
Zverev:Djokovic:7-5,7-5 Thiem 4 8 56 532 52
Williams:Muguruza:3-6,6-3,6 512
-3 Zverev 4 4 32 286 2
Muguruza:Williams:6-4,6-4 6 284
Williams:Muguruza:2-6,6-2,6
-0
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Barty:Medvedev:6-3,4-6,6-4,
6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4
Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Barty:7-5,7-5
Halep:Barty:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Barty:Thiem:6-3,4-6,7-6,0-
6,7-5
Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Barty:Medvedev:6-3,4-6,6-4,
6-3
Medvedev:Thiem:6-0,7-6,6-7,

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 7/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4
Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Barty:7-5,7-5
Halep:Barty:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Barty:Thiem:6-3,4-6,7-6,0-
6,7-5
Djokovic:Zverev:2-6,6-7,7-
6,6-3,6-1
Zverev:Djokovic:6-3,4-6,6-
4,6-3
Djokovic:Zverev:6-0,7-6,6-
7,6-3
Zverev:Djokovic:6-4,6-4
Djokovic:Zverev:2-6,6-2,6-0
Zverev:Djokovic:6-3,4-6,6-
3,6-4
Djokovic:Zverev:7-6,4-6,7-
6,2-6,6-2
Zverev:Djokovic:7-5,7-5
Williams:Muguruza:3-6,6-3,6
-3
Muguruza:Williams:6-4,6-4
Williams:Muguruza:2-6,6-2,6
-0
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Barty:Medvedev:6-3,4-6,6-4,
6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 8/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Barty:7-5,7-5
Halep:Barty:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Barty:Thiem:6-3,4-6,7-6,0-
6,7-5
Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Barty:Medvedev:6-3,4-6,6-4,
6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Thiem:Medvedev:6-4,6-4
Halep:Medvedev:2-6,6-2,6-0
Thiem:Medvedev:6-3,4-6,6-3,
6-4
Medvedev:Thiem:7-6,4-6,7-6,
2-6,6-2
Thiem:Barty:7-5,7-5
Halep:Barty:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Barty:Thiem:6-3,4-6,7-6,0-
6,7-5

Federer:Djokovic:2-6,6-7,7-
6,6-3,6-1
Djokovic:Federer:6-3,4-6,6-
4,6-3
Federer:Djokovic:6-0,7-6,6-
7,6-3 Federer 3 1 13 142
Djokovic:Federer:6-4,6-4 16 143
Test Federer:Djokovic:2-6,6-2,6- Djokovic 2 2 16 143
Case 7 0 13 142
Djokovic:Federer:6-3,4-6,6- Halep 0 1 2 15 1 12
3,6-4 Barty 0 0 1 12 2 15
Federer:Djokovic:7-6,4-6,7-
6,2-6,6-2
Djokovic:Federer:7-5,7-5
Halep:Barty:3-6,6-3,6-3

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 9/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

Halep:Medvedev:2-6,6-7,7-6,
6-3,6-1
Williams:Medvedev:6-3,4-6,6
-4,6-3
Medvedev:Thiem:6-0,7-6,6-7,
6-3
Halep 2 2 10 75 6 6
Thiem:Medvedev:6-4,6-4
0
Halep:Medvedev:2-6,6-2,6-0
Medvedev 2 0 11 122
Thiem:Medvedev:6-3,4-6,6-3,
Test 16 139
6-4
Case 8 Williams 2 0 7 68 7
Medvedev:Thiem:7-6,4-6,7-6,
71
2-6,6-2
Thiem 1 2 14 133 13
Thiem:Williams:7-5,7-5
128
Halep:Williams:3-6,6-3,6-3
Halep:Thiem:0-6,0-6,6-0,6-
0,7-5
Williams:Thiem:6-3,4-6,7-6,
0-6,7-5

Djokovic:Zverev:2-6,6-7,7-
6,6-3,6-1
Zverev:Djokovic:6-3,4-6,6-
4,6-3
Djokovic:Zverev:6-0,7-6,6-
7,6-3
Zverev:Djokovic:6-4,6-4
Djokovic:Zverev:2-6,6-2,6-0
Zverev:Djokovic:6-3,4-6,6-
3,6-4
Djokovic:Zverev:7-6,4-6,7-
6,2-6,6-2
Williams 3 2 16 160
Zverev:Djokovic:7-5,7-5
16 146
Williams:Muguruza:3-6,6-3,6
Muguruza 3 1 16 146
-3
Test 16 160
Muguruza:Williams:6-4,6-4
Case 9 Djokovic 3 1 13 142
Williams:Muguruza:2-6,6-2,6
16 143
-0
Zverev 2 2 16 143 1
Muguruza:Williams:6-3,4-6,6
3 142
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3
Muguruza:Williams:6-3,4-6,6
-4,6-3
Williams:Muguruza:6-0,7-6,6
-7,6-3

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 10/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

The due date for submitting this assignment has passed.


As per our records you have not submitted this assignment.
Sample solutions (Provided by instructor)
1 # Statistics will be stored as a dictionary
2 # Each key is a player name, each value is a list of 6 integers
3 # representing
4 # Best of 5 set matches won,
5 # Best of 3 set matches won,
6 # Sets won
7 # Games won
8 # Sets lost (store as negative number for comparison)
9 # Games lost (store as negative number for comparison)
10 stats = {}
11
12 # Read a line of input
13 line = input()
14 while line:
15 # Keep track of sets/games won and lost in this match
16 # with respect to winner of the match
17 (wsets,lsets,wgames,lgames) = (0,0,0,0)
18
19 # Extract winner, loser and string of setscores
20 (winner,loser,setscores) = line.strip().split(':',2)
21
22 # Extract sequence of sets from setscores
23 sets = setscores.split(',')
24
25 for set in sets:
26 # Process each set
27 (winstr,losestr) = set.split('-')
28 win = int(winstr)
29 lose = int(losestr)
30 wgames = wgames + win
31 lgames = lgames + lose
32 if win > lose:
33 wsets = wsets + 1
34 else:
35 lsets = lsets + 1
36
37 # Update statistics for each of the players
38
39 for player in [winner,loser]:
40 try:
41 stats[player]
42 except KeyError:
43 stats[player] = [0,0,0,0,0,0]
44
45 if wsets >= 3:
46 stats[winner][0] = stats[winner][0] + 1
47 else:
48 stats[winner][1] = stats[winner][1] + 1
49
50 stats[winner][2] = stats[winner][2] + wsets
51 stats[winner][3] = stats[winner][3] + wgames
52 stats[winner][4] = stats[winner][4] - lsets
53 stats[winner][5] = stats[winner][5] - lgames
54
55 stats[loser][2] = stats[loser][2] + lsets
56 stats[loser][3] = stats[loser][3] + lgames
57 stats[loser][4] = stats[loser][4] - wsets
58 stats[loser][5] = stats[loser][5] - wgames
59
60 line = input()
61
62 # Collect each player's stats as a tuple, name last
63 statlist = [(stat[0],stat[1],stat[2],stat[3],stat[4],stat[5],name) for
64
65 # Sort the statistics in descending order
66 # Losing games are stored negatively for sorting correctly
67 statlist.sort(reverse = True)
68
69 # Print
70 for entry in statlist:
71 print(entry[6],entry[0],entry[1],entry[2],entry[3], -entry[4], -ent
72
73

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 11/12
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course

https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=95 12/12

You might also like