Question 53 of 97
Q.(A) 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
(OR)
(B) Write a user defined function in Python named Puzzle(W,N) which takes the argument W as an English word and N as an integer and returns the string where every Nth alphabet of the word W is replaced with an underscore ("_"). For example: if W contains the word "TELEVISION" and N is 3, then the function should return the string "TE_EV_SI_N". Likewise for the word "TELEVISION" if N is 4, then the function should return "TEL_VIS_ON".
Sikkim CbseCBSE Class XII Board 2024Subjective· 2mImportance★★★★★
55% · 53/97 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a) computes each student's average of three marks and prints a grade (A/B/C); Part (b) returns the word with every Nth character replaced by an underscore.
Part (a)
Each key of S is a student name and its value is a list [Eng, Math, Science].
Approach
- Loop over
S.items()to get each name and its marks list. avg = sum(marks) / 3.- Grade:
avg >= 90→ A, elseavg >= 60→ B, else C. - Print
name - grade.
def showGrades(S):
for name, marks in S.items():
avg = sum(marks) / 3
if avg >= 90:
grade = 'A'
elif avg >= 60:
grade = 'B'
else:
grade = 'C'
print(name, "-", grade)
S = {"AMIT":[92,86,64], "NAGMA":[65,42,43], "DAVID":[92,90,88]}
showGrades(S)
Trace — AMIT: (92+86+64)/3 = 80.67 → B; NAGMA: 150/3 = 50 → C; DAVID: 270/3 = 90 → A.
AMIT - B
NAGMA - C
DAVID - A …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.