Advertisements
Advertisements
Question
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
S={"AMIT": [92, 86, 64], "NAGMA": [65, 42, 43], "DAVID": [92, 90, 88]}
The output should be:
AMIT - B
NAGMA - C
DAVID - A
Code Writing
Solution
def showGrades(S):
for n, marks in S.items():
perc=sum(marks)/3
if perc>=90:
print(n + ":" + "A")
elif perc>=60:
print(n + ":" + "B")
else:
print(n + ":" + "C")
shaalaa.com
Is there an error in this question or solution?