Programming Data Structure And Algorithms Using Python | Week 5
Session: JULY-DEC 2023
Course Name: Programming Data Structure And Algorithms Using Python
Course Link: Click Here
These are Programming Data Structure And Algorithms Assignment 5 Answers
Programming Data Structure And Algorithms Using Python Programming Assignment Question
Question 1
The academic office at the Hogwarts School of Witchcraft and Wizardry has compiled data about students’ grades. The data is provided as text from standard input in three parts: information about courses, information about students and information about grades. Each part has a specific line format, described below.
Information about courses
Line format: Course Code~Course Name~Semester~Year~Instructor
Information about students
Line format: Roll Number~Full Name
Information about grades
Line format: Course Code~Semester~Year~Roll Number~Grade
The possible grades are A, AB, B, BC, C, CD, D with corresponding grade points 10, 9, 8, 7, 6, 5 and 4. The grade point average of a student is the sum of his/her grade points divided by the number of courses. For instance, if a student has taken two courses with grades A and C, the grade point average is 8.50 = (10+7)÷2. If a student has not completed any courses, the grade point average is defined to be 0.
You may assume that the data is internally consistent. For every grade, there is a corresponding course code and roll number in the input data.
Each section of the input starts with a line containing a single keyword. The first section begins with a line containing Courses. The second section begins with a line containing Students. The third section begins with a line containing Grades. The end of the input is marked by a line containing EndOfInput.
Write a Python program to read the data as described above and print out a line listing the grade point average for each student in the following format:
Roll Number~Full Name~Grade Point Average
Your output should be sorted by Roll Number. The grade point average should be rounded off to 2 digits after the decimal point. Use the built-in function round().
Answer:
def Gvalue(code1):
if code1=="A":
return(10)
if code1=="AB":
return(9)
if code1=="B":
return(8)
if code1=="BC":
return(7)
if code1=="C":
return(6)
if code1=="CD":
return(5)
if code1=="D":
return(4)
# varibles used for storing data
ROLL_GRADEsum={}
Roll_course_count={}
Roll_name={}
#COURSES INPUT SECTION
type_course=input()
enter_course_detail=input()
next_input=input()
while(next_input!="Students"):
next_input=input()
#STUDENT INPUT SECTION
#if it fails in courses section then
#it will automatically enter students
#contact us
roll,name=input().split('~')
Roll_name[roll]=name
ROLL_GRADEsum[roll]=0
Roll_course_count[roll]=0
next_input=input()
while('~' in next_input):
roll,name=next_input.split('~')
Roll_name[roll]=name
ROLL_GRADEsum[roll]=0
Roll_course_count[roll]=0
next_input=input()
#GRADES INPUT SECTION
code,sem,year,Rnum,grade=input().split('~')
if Rnum in ROLL_GRADEsum.keys():
ROLL_GRADEsum[Rnum]=ROLL_GRADEsum[Rnum]+Gvalue(grade)
Roll_course_count[Rnum]=Roll_course_count[Rnum]+1
next_input=input()
while(next_input!="EndOfInput"):
code,sem,year,Rnum,grade=next_input.split('~')
if Rnum in ROLL_GRADEsum.keys():
ROLL_GRADEsum[Rnum]=ROLL_GRADEsum[Rnum]+Gvalue(grade)
Roll_course_count[Rnum]=Roll_course_count[Rnum]+1
next_input=input()
#print(Roll_course_count)
#print(ROLL_GRADEsum)
#print(Roll_name)
#RESULT COMPUTATION
Sort_roll=sorted(Roll_name)
for key in Sort_roll:
if ROLL_GRADEsum[key]!=0:
ans=round((ROLL_GRADEsum[key]/Roll_course_count[key]),2)
print(key+"~"+Roll_name[key]+"~"+str(ans))
else:
print(key+"~"+Roll_name[key]+"~"+"0")
These are Programming Data Structure And Algorithms Assignment 5 Answers
More Weeks of Programming Data Structure And Algorithms Using Python: Click here
More Nptel Courses: Click here
Session: JAN-APR 2023
Course Name: Programming Data Structure And Algorithms Using Python
Course Link: Click Here
These are Programming Data Structure And Algorithms Assignment 5 Answers
Programming Assignment
The library at the Hogwarts School of Witchcraft and Wizardry has computerized its book issuing process. The relevant information is provided as text from standard input in three parts: information about books, information about borrowers and information about checkouts. Each part has a specific line format, described below.
- Information about books
Line format: Accession Number~Title - Information about borrowers
Line format: Username~Full Name - Information about checkouts
Line format: Username~Accession Number~Due Date
Note: Due Date is in YYYY-MM-DD format.
These are Programming Data Structure And Algorithms Assignment 5 Answers
You may assume that the data is internally consistent. For every checkout, there is a corresponding username and accession number in the input data, and no book is simultaneously checked out by two people.
These are Programming Data Structure And Algorithms Assignment 5 Answers
Each section of the input starts with a line containing a single keyword. The first section begins with a line containing Books. The second section begins with a line containing Borrowers. The third section begins with a line containing Checkouts. The end of the input is marked by a line containing EndOfInput.
Write a Python program to read the data as described above and print out details about books that have been checked out. Each line should describe to one currently issued book in the following format:
Due Date~Full Name~Accession Number~Title
These are Programming Data Structure And Algorithms Assignment 5 Answers
Your output should be sorted in increasing order of due date. For books due on the same date, sort in increasing order of full name.
Here is a sample input and its corresponding output.
Solution:
books = dict()
# Dictionary to map username to fullname
borrowers = dict()
# List to store checkout data: accumulate, sort and print
checkouts = []
# Find the start of Books data
nextline = input().strip()
while nextline.find("Books") < 0:
nextline = input().strip()
# Read upto start of Borrowers data
# Skip the line with "Books"
nextline = input().strip()
while nextline.find("Borrowers") < 0:
(accession_number,title) = nextline.split('~')
books[accession_number] = title
nextline = input().strip()
# Read upto Checkout data
# Skip the line with "Borrowers"
nextline = input().strip()
while nextline.find("Checkouts") < 0:
(username,fullname) = nextline.split('~')
borrowers[username] = fullname
nextline = input().strip()
# Process Checkouts
# Skip the line with "Checkouts"
nextline = input().strip()
while nextline.find("EndOfInput") < 0:
(username,accession_number,due_date) = nextline.split('~')
checkoutline = due_date+"~"+borrowers[username]+"~" + accession_number+"~"+ books[accession_number]
checkouts.append(checkoutline)
nextline = input().strip()
# Print the output from checkouts
for i in sorted(checkouts):
print(i)
These are Programming Data Structure And Algorithms Assignment 5 Answers
More Weeks of Programming Data Structure And Algorithms: Click Here
More Nptel courses: https://progiez.com/nptel
Session: JULY-DEC 2022
Course Name: Programming Data Structure And Algorithms Using Python
Link of Course: Click Here
These are Programming Data Structure And Algorithms Assignment 5 Answers
Question 1
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.
These are Programming Data Structure And Algorithms Assignment 5 Answers
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).
These are Programming Data Structure And Algorithms Assignment 5 Answers
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 s<=ks<=5
For example, an input line of the form
Osaka : Barty : 3-6,6-3,6-3
indicates that Osaka beat Barty 3-6, 6-3, 6-3 in a best of 3 set match.
These are Programming Data Structure And Algorithms Assignment 5 Answers
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
These are Programming Data Structure And Algorithms Assignment 5 Answers
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
These are Programming Data Structure And Algorithms Assignment 5 Answers
Zverev : Medvedev : 2-6, 6-7,7-6,6-3,6-1
Barty : Osaka : 6-4,6-4
Medvedev : Zverev : 6-3,6-3
Osaka : Barty : 1-6,7-5,6-2
Zverev : Medvedev : 6-0,7-6, 6-3
Osaka : Barty : 2-6,6-2,6-0
Medvedev : Zverev : 6-3,4-6,6-3,6-4
Barty : Osaka : 6-1,3-6,7-5
Zverev : Medvedev : 7-6,4-6, 7-6,2-6, 6-2
Osaka : Barty : 6-4,1-6, 6-3
Medvedev : Zverev : 7-5,7-5
Osaka : Barty : 3-6,6-3,6-3
your program should print out the following
Zverev 3 0 10 104 11 186
Medvedev 1 2 11 106 10 104
Osaka 0 4 9 76 8 74
Barty 0 2 8 74 9 76
Solution:
//Code
These are Programming Data Structure And Algorithms Assignment 5 Answers
More NPTEL Solutions: https://progiez.com/nptel