Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

Programming, Data Structures And Algorithms Using Python | Week 5 Programming Assignment | Jan-2022 | NPTEL

 Programming, Data Structures And Algorithms Using Python



Week 5 Programming Assignment

Due on 2022-03-03, 23:59 IST

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.
  • In all cases you may assume that the input to your program has the expected format, so your program does not have to check for malformed inputs.
  • 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".


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..

  1. Information about courses
    Line format: Course Code~Course Name~Semester~Year~Instructor
  2. Information about students
    Line format: Roll Number~Full Name
  3. 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().

Here is a sample input and its corresponding output.

Sample Input

Courses
TRAN~Transfiguration~1~2011-2012~Minerva McGonagall
CHAR~Charms~1~2011-2012~Filius Flitwick
Students
SLY2301~Hannah Abbott
SLY2302~Euan Abercrombie
SLY2303~Stewart Ackerley
SLY2304~Bertram Aubrey
SLY2305~Avery
SLY2306~Malcolm Baddock
SLY2307~Marcus Belby
SLY2308~Katie Bell
SLY2309~Sirius Orion Black
Grades
TRAN~1~2011-2012~SLY2301~AB
TRAN~1~2011-2012~SLY2302~B
TRAN~1~2011-2012~SLY2303~B
TRAN~1~2011-2012~SLY2305~A
TRAN~1~2011-2012~SLY2306~BC
TRAN~1~2011-2012~SLY2308~A
TRAN~1~2011-2012~SLY2309~AB
CHAR~1~2011-2012~SLY2301~A
CHAR~1~2011-2012~SLY2302~BC
CHAR~1~2011-2012~SLY2303~B
CHAR~1~2011-2012~SLY2305~BC
CHAR~1~2011-2012~SLY2306~C
CHAR~1~2011-2012~SLY2307~B
CHAR~1~2011-2012~SLY2308~AB
EndOfInput

Sample Input

SLY2301~Hannah Abbott~9.5
SLY2302~Euan Abercrombie~7.5
SLY2303~Stewart Ackerley~8.0
SLY2304~Bertram Aubrey~0
SLY2305~Avery~8.5
SLY2306~Malcolm Baddock~6.5
SLY2307~Marcus Belby~8.0
SLY2308~Katie Bell~9.5
SLY2309~Sirius Orion Black~9.0

Just scroll your mouse wheel over this code or swipe on this code snippet to scroll down to see the remaining code.

Select the Language for this assignment. 
1
def gpa():

	courses  = []
	students = {}
	grades   = {}
	while True:
		s = input()
		if s == "Courses":
			d = 1
		elif s == "Students":
			d = 2
		elif s == "Grades":
			d = 3
		elif s == "EndOfInput":	
			break

		else:

			s = s.split("~")
			if d == 1:
				courses.append(s)
			elif d == 2:
				students[s[0]] = s[1]
				grades[s[0]] = []
			elif d == 3:

				grades[s[-2]].append(s[-1])


	points = {"A":10, "AB":9, "B":8, "BC":7, "C":6, "CD":5, "D":4}

	for idx in sorted(grades):

		p = [points[x] for x in grades[idx]]

		n = len(p) or 1

		marks = str(round(sum(p)/n,2)) if p else "0"

		d = [idx,students[idx],marks]

		print("~".join(d))

gpa()
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.



 
 

Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Courses
TRAN~Transfiguration~1~2011-2012~Minerva McGonagall
CHAR~Charms~1~2011-2012~Filius Flitwick
Students
SLY2301~Hannah Abbott
SLY2302~Euan Abercrombie
SLY2303~Stewart Ackerley
SLY2304~Bertram Aubrey
SLY2305~Avery
SLY2306~Malcolm Baddock
SLY2307~Marcus Belby
SLY2308~Katie Bell
SLY2309~Sirius Orion Black
Grades
TRAN~1~2011-2012~SLY2301~AB
TRAN~1~2011-2012~SLY2302~B
TRAN~1~2011-2012~SLY2303~B
TRAN~1~2011-2012~SLY2305~A
TRAN~1~2011-2012~SLY2306~BC
TRAN~1~2011-2012~SLY2308~A
TRAN~1~2011-2012~SLY2309~AB
CHAR~1~2011-2012~SLY2301~A
CHAR~1~2011-2012~SLY2302~BC
CHAR~1~2011-2012~SLY2303~B
CHAR~1~2011-2012~SLY2305~BC
CHAR~1~2011-2012~SLY2306~C
CHAR~1~2011-2012~SLY2307~B
CHAR~1~2011-2012~SLY2308~AB
EndOfInput
SLY2301~Hannah Abbott~9.5\n
SLY2302~Euan Abercrombie~7.5\n
SLY2303~Stewart Ackerley~8.0\n
SLY2304~Bertram Aubrey~0\n
SLY2305~Avery~8.5\n
SLY2306~Malcolm Baddock~6.5\n
SLY2307~Marcus Belby~8.0\n
SLY2308~Katie Bell~9.5\n
SLY2309~Sirius Orion Black~9.0\n
SLY2301~Hannah Abbott~9.5\n
SLY2302~Euan Abercrombie~7.5\n
SLY2303~Stewart Ackerley~8.0\n
SLY2304~Bertram Aubrey~0\n
SLY2305~Avery~8.5\n
SLY2306~Malcolm Baddock~6.5\n
SLY2307~Marcus Belby~8.0\n
SLY2308~Katie Bell~9.5\n
SLY2309~Sirius Orion Black~9.0\n
Passed
Test Case 2
Courses
POT~Potions~1~2011-2012~Severus Snape
DADA~Defence Against the Dark ARTS~1~2011-2012~Gilderoy Lockhart 
Students
RAV4309~Angelina Johnson
HUF7201~Gwenog Jones
GRF9110~Parvati Patil
RAV4308~Olive Hornby
Grades
POT~1~2011-2012~RAV4308~C
POT~1~2011-2012~RAV4309~B
POT~1~2011-2012~GRF9110~A
EndOfInput
GRF9110~Parvati Patil~10.0\n
HUF7201~Gwenog Jones~0\n
RAV4308~Olive Hornby~6.0\n
RAV4309~Angelina Johnson~8.0\n
GRF9110~Parvati Patil~10.0\n
HUF7201~Gwenog Jones~0\n
RAV4308~Olive Hornby~6.0\n
RAV4309~Angelina Johnson~8.0\n
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed
Test Case 4
Passed
Test Case 5
Passed
Test Case 6
Passed


Please subscribe to our YouTube Channel :  Swayam Solver

This will help the creator to continue making quality content...

Have a great day !



No comments:

Post a Comment

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.