Finding the percentage | HackerRank
Finding the percentage | HackerRank
Store a list of students and marks in a dictionary, and find the average marks obtained by a student.
www.hackerrank.com
Goal
Print the average of the marks array for the given student name and showing 2 places after the decimal.
Solution
First, we need to get average score from the give student marks.
Secondly, we need to print out only 2 places after the decimal.
I use {:.2f} format to show 2 places after the decimal. But there are other ways too.
# Finding the percentage
if __name__ == '__main__':
n = int(input())
student_marks = {}
for _ in range(n):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
query_scores = [x for x in student_marks[query_name]]
print("{:.2f}".format(float(sum(query_scores)) / len(query_scores)))
'software Engineering > (Python)HackerRank' 카테고리의 다른 글
| [Python] HackerRank - sWAP cASE (0) | 2023.02.03 |
|---|---|
| [Python] HackerRank - Lists (0) | 2023.02.02 |
| [Python] HackerRank - Nested Lists (0) | 2023.01.31 |
| [Python] HackerRank - Find the Runner-Up Score! (0) | 2023.01.29 |
| [Python] HackerRank -List Comprehensions (0) | 2023.01.28 |