Home > OS >  Grading a student with the marks given in the form of a dictionary
Grading a student with the marks given in the form of a dictionary

Time:10-16

Ramesh is the principal of a school. Every year, he appoints some teachers to calculate the grades of students from the marks scored by them. Since technology is evolving Ramesh wants to digitize this process. So, he decided to hire a programmer for this task.

You are given a dictionary where the keys are the name, and the values are another dictionary that contains subjects as keys and marks as values. Write a function convertMarks that takes a dictionary as an argument and returns a dictionary with marks replaced with grades.

The principal has also provided the grades associated with the range of marks.

(Note: Both endpoints are included)

1 Grade - Marks 2 ​ 3 A - 91-100 4 B - 81 - 90 5 C - 71 - 80 6 D - 61 - 70 7 E - 51 - 60 8 E - 41 - 50 9 F - 0 - 40 10 ​

Example input

{‘Lakshman’: {‘Maths’: 90, ‘English’: 75, ‘Social Science’: 10}

Example output

{‘Lakshman’: {‘Maths’: B, ‘English’: C, ‘Social Science’: F}

CodePudding user response:

def converMarks(d):
for students in d.keys():
    for marks in d[students].keys():
        m = d[students][marks]
        if m>=91 and m<=100:
            d[students][marks] = 'A'
        elif m>=81 and m<=90:
            d[students][marks] = 'B'
        elif m>=71 and m<=80:
            d[students][marks] = 'C'
        elif m>=61 and m<=70:
            d[students][marks] = 'D'
        elif m>=51 and m<=60:
            d[students][marks] = 'E '
        elif m>=41 and m<=50:
            d[students][marks] = 'E'
        elif m>=0 and m<=40:
            d[students][marks] = 'F'
return d


name = input().split()

d = {}
for i in name:
    d[i] = {}
    subjects = input().split()
    marks = input().split()
    for j in range(len(subjects)):
        d[i][subjects[j]] = int(marks[j])

print(converMarks(d))

CodePudding user response:

         def converMarks(d):
for students in d.keys():
    for marks in d[students].keys():
        m = d[students][marks]
        if m>=91 and m<=100:
            d[students][marks] = 'A'
        elif m>=81 and m<=90:
            d[students][marks] = 'B'
        elif m>=71 and m<=80:
            d[students][marks] = 'C'
        elif m>=61 and m<=70:
            d[students][marks] = 'D'
        elif m>=51 and m<=60:
            d[students][marks] = 'E '
        elif m>=41 and m<=50:
            d[students][marks] = 'E'
        elif m>=0 and m<=40:
            d[students][marks] = 'F'
return d
  • Related