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:
\[ \begin{array}{|c|c|} \hline \textbf{Average of Eng, Math, Science} & \textbf{Grade} \\ \hline \geq 90 & A \\ \hline < 90 \text{ but } \geq 60 & B \\ \hline < 60 & C \\ \hline \end{array} \]
Example: Consider the following dictionary: \[ S = \{\text{"AMIT"}: [92, 86, 64], \text{"NAGMA"}: [65, 42, 43], \text{"DAVID"}: [92, 90, 88]\} \] The output should be: \[ \text{AMIT} - B \\ \text{NAGMA} - C \\ \text{DAVID} - A \]
def showGrades(S): # Function definition
for name, marks in S.items(): # Loop through each student and their marks
avg = sum(marks) / len(marks) # Calculate the average of marks
if avg > 90: # Check for grade A
grade = "A"
elif avg > 60: # Check for grade B
grade = "B"
else: # Check for grade C
grade = "C"
print(f"{name} - {grade}") # Print the name and grade
# Example dictionary
S = {"AMIT": [92, 86, 64], "NAGMA": [65, 42, 43], "DAVID": [92, 90, 88]}
showGrades(S) # Call the function
Explanation:
The function showGrades(S) iterates through the dictionary S, where each key is a student's name, and the value is a list of marks in English, Math, and Science.
The average is calculated using sum(marks) / len(marks).
Grades are assigned based on the average using the conditions:
- If the average is greater than or equal to 90, the grade is "A".
- If the average is less than 90 but greater than or equal to 60, the grade is "B".
- If the average is less than 60, the grade is "C".
The result is printed in the format Name - Grade.
myStr[:4] extracts the first 4 characters, which are "MISS".myStr[-5:] extracts the last 5 characters, which are "SIPPI"."#" in between, resulting in "MISS#SIPPI".
event = "G20 Presidency@2023"
L = event.split(' ')
print(L[::-2])
Consider the following Python statement:
F = open('CONTENT.TXT')
Which of the following is an invalid statement in Python?
What did the hunters decide to do when they realized that the tiger was not dead? (The Tiger King)
Alexia Limited invited applications for issuing 1,00,000 equity shares of ₹ 10 each at premium of ₹ 10 per share.
The amount was payable as follows:
Applications were received for 1,50,000 equity shares and allotment was made to the applicants as follows:
Category A: Applicants for 90,000 shares were allotted 70,000 shares.
Category B: Applicants for 60,000 shares were allotted 30,000 shares.
Excess money received on application was adjusted towards allotment and first and final call.
Shekhar, who had applied for 1200 shares failed to pay the first and final call. Shekhar belonged to category B.
Pass necessary journal entries for the above transactions in the books of Alexia Limited. Open calls in arrears and calls in advance account, wherever necessary.
“One of these days you’re going to talk yourself into a load of trouble,” her father said aggressively. What do you learn about Sophie’s father from these lines? (Going Places)