Table of Contents
Read from a dictionary containing key/value pairs of name:[marks] for a list of students.
Read from a dictionary containing key/value pairs of name:[marks] for a list of students. Print the average of the marks array for the student name provided, showing 2 places after the decimal.
Finding the percentage hackerrank problem
Sample Input
2 Will 15 5 10 Mike 9 7 23 Will
Output Format
Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.
10.00
How to print a float with two decimal places in Python?
Format the float with two decimal places:
float_num = 3.14159265358 formatted_float = "{:.2f}".format(float_num) print(formatted_float) //3.14
How to sum a list of numbers in Python?
Python provide an inbuilt function sum() which sums up the numbers in the list.
How to Find the Length of List in Python?
The len() function returns how many elements are in a list.
The len of the string is a number of characters, while the length of the list is a number of elements it holds.
Solution
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 = student_marks[query_name] print("{0:.2f}".format(sum(query_scores)/(len(query_scores))))
Hello there!
I hope you find this post useful!I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.
If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!