CBSE · 083Class XII · 2024Section B2 marks
Question 21
2 April 2024 · Computer Science (083)
Write a user defined function in Python named showGrades(S) which takes the dictionary S as an argument. The dictionary, S contains Name:[Eng,Math,Science] as key:value pairs. The function displays the corresponding grade obtained by the students according to the following grading rules :
| Average of Eng,Math,Science | Grade |
|---|---|
| >=90 | A |
| <90 but >=60 | B |
| <60 | C |
For example : Consider the following dictionary
python
S = {"AMIT":[92,86,64], "NAGMA":[65,42,43], "DAVID":[92,90,88]}The output should be :
text
AMIT - B
NAGMA - C
DAVID - AAnswer
python
def showGrades(S):
for K, V in S.items():
if sum(V)/3 >= 90:
Grade = "A"
elif sum(V)/3 >= 60:
Grade = "B"
else:
Grade = "C"
print(K, "-", Grade)Explanation
Iterates through the dictionary items, computes the average of each value list, and prints the corresponding grade.