Solution :-

Download Python File :- Download

import operator

input('')

class Stu:
    def __init__(self, name, fname):
        self.name = name
        self.fname = fname
        self.num = 0
        self.total = 0

    def add(self, gr):
        self.num +=1
        if gr=="A":
            self.total +=10
        elif gr=="AB":
            self.total+=9
        elif gr=="B":
            self.total+=8
        elif gr=="BC":
            self.total+=7
        elif gr=="C":
            self.total+=6
        elif gr=="CD":
            self.total+=5
        elif gr=="D":
            self.total+=4

class Marks:
    def __init__(self, sub, scode, grade):
        self.sub = sub
        self.scode = scode
        self.grade = grade

ss=[]
mm=[]

flag = True

z= input('')
while True:
    z= input('')
    xxx = z.split('~')
    if len(xxx)==1 or len(xxx)==0:
        break
    if len(z)==0:
        break

z= input('')
while True:
    xxx = z.split('~')
    if len(xxx)==1 or len(xxx)==0:
        break
    a,b = xxx
    x= Stu(a,b)
    ss.append(x)
    z= input('')
    if len(z)==0:
        break

z= input('')

while True:
    xxx = z.split('~')
    if len(xxx)==1:
        break
    a,b,c,d,e = xxx
    x= Marks(a,d,e)
    mm.append(x)
    z= input('')
    if len(z)==0:
        break

def ser(ss,tos):
    for s in ss:
        if s.name==tos:
            return s

for m in mm:
    ser(ss,m.scode).add(m.grade)

ss.sort(key=operator.attrgetter('name'))

for s in ss:
    if s.num == 0:
        fff=0
        print(s.name + "~"+s.fname +"~"+str(fff))
    else:
        fff =float(s.total) /float(s.num)
        print(s.name + "~"+ s.fname+ "~" + str(round(fff,2)))

 

Categories: NPTEL solution

20 Comments

Mayuresh · September 2, 2017 at 2:40 PM

Thank you so much sir

Ruban B · September 2, 2017 at 3:15 PM

Please upload the WEEK-5 ASSIGNMENT FOR INTRODUCTION TO ALGORITHM AND ANALYSIS

    Mit Patel · September 5, 2017 at 7:26 PM

    The solution is posted.

Sarang · September 2, 2017 at 4:07 PM

hello sir,
first of all, thanks for assignment-5 sol of Python, I stuck on many conditions your program help me.Sir if possible, please explain program line by line as Python interpreter works

Unknown · September 2, 2017 at 4:15 PM

Thanks a lot

Nikhil P · September 2, 2017 at 4:18 PM

Thank You sir..

Prathmesh · September 2, 2017 at 4:46 PM

Sir I am getting only 83.33 as the score

    Mit Patel · September 5, 2017 at 7:25 PM

    The code has been updated.

Bikram Bhattacharya · September 2, 2017 at 5:05 PM

But I am getting 83.333/100. why? Please check quickly and provide the correct solution.
Thank you.

    Mit Patel · September 5, 2017 at 7:25 PM

    The code is updated for 100/100

abhishek · September 2, 2017 at 5:16 PM

can u please explain the 82 line of code?

Bikram Bhattacharya · September 2, 2017 at 6:12 PM

Here is the code for 100/100
import operator

input(”)

class Stu:
def __init__(self, name, fname):
self.name = name
self.fname = fname
self.num = 0
self.total = 0

def add(self, gr):
self.num +=1
if gr==”A”:
self.total +=10
elif gr==”AB”:
self.total+=9
elif gr==”B”:
self.total+=8
elif gr==”BC”:
self.total+=7
elif gr==”C”:
self.total+=6
elif gr==”CD”:
self.total+=5
elif gr==”D”:
self.total+=4

class Marks:
def __init__(self, sub, scode, grade):
self.sub = sub
self.scode = scode
self.grade = grade

ss=[]
mm=[]

flag = True

z= input(”)
while True:
z= input(”)
xxx = z.split(‘~’)
if len(xxx)==1 or len(xxx)==0:
break
if len(z)==0:
break

z= input(”)
while True:
xxx = z.split(‘~’)
if len(xxx)==1 or len(xxx)==0:
break
a,b = xxx
x= Stu(a,b)
ss.append(x)
z= input(”)
if len(z)==0:
break

z= input(”)

while True:
xxx = z.split(‘~’)
if len(xxx)==1:
break
a,b,c,d,e = xxx
x= Marks(a,d,e)
mm.append(x)
z= input(”)
if len(z)==0:
break

def ser(ss,tos):
for s in ss:
if s.name==tos:
return s

for m in mm:
ser(ss,m.scode).add(m.grade)

ss.sort(key=operator.attrgetter(‘name’))

for s in ss:
if s.num == 0:
fff=0
print(s.name + “~”+s.fname +”~”+str(fff))
else:
fff =float(s.total) /float(s.num)
print(s.name + “~”+ s.fname+ “~” + str(round(fff,2)))

Thank you

mahesh · September 3, 2017 at 2:53 PM

some bug in this program,it is passing all the cases but the score is reduced to 83.3 out of 100 while submitting this code

    Mit Patel · September 5, 2017 at 7:20 PM

    The problem has been solved. Keep visiting 🙂

coder · September 3, 2017 at 3:32 PM

sir can this problem be solved without using the concept of class,as in our course in nptel we have not been taught the concept of class in python yet

aa · September 4, 2017 at 11:52 AM

thank u so much sir

    Mit Patel · September 5, 2017 at 7:16 PM

    Thanks for connecting with us. Keep visiting.

viji · September 4, 2017 at 3:05 PM

can you please upload this program without class.

Mayuresh · September 13, 2017 at 5:18 PM

Sir please upload programming assignment 8

Aryan · September 16, 2017 at 7:32 AM

Hi there , Post Week 8 programming assignment solution 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *