We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
name = 'Asia Alice'
result = find_percentage(student_scores, name)
print(f"{name}'s percentage: {result}%")
This solution defines a function find_percentage that takes a dictionary student_scores and a student_name as input. It calculates the total score of the student and divides it by the number of subjects to find the percentage. If the given student name is not found in the dictionary, it returns an appropriate message indicating that the student was not found. The example usage demonstrates how to use the function with sample data.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Finding the percentage
You are viewing a single comment's thread. Return to all comments →
Sure, here's a short solution for the problem "Finding the percentage":
Problem: Given a dictionary containing student names and their corresponding scores in a subject, find the percentage score of a specific student.
Solution:
python Copy code def find_percentage(student_scores, student_name): if student_name in student_scores: total_score = sum(student_scores[student_name]) num_subjects = len(student_scores[student_name]) percentage = total_score / num_subjects return percentage else: return f"Student '{student_name}' not found."
Example usage:
student_scores = { 'Alice': [85, 90, 78], 'Bob': [92, 88, 95], 'Charlie': [78, 85, 80] }
name = 'Asia Alice' result = find_percentage(student_scores, name) print(f"{name}'s percentage: {result}%") This solution defines a function find_percentage that takes a dictionary student_scores and a student_name as input. It calculates the total score of the student and divides it by the number of subjects to find the percentage. If the given student name is not found in the dictionary, it returns an appropriate message indicating that the student was not found. The example usage demonstrates how to use the function with sample data.