Finding The Percentage (HackerRank)

 The provided code stub will read in 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.

Example



The query_name is 'beta'. beta's average score is .

Input Format

The first line contains the integer , the number of students' records. The next  lines contain the names and marks obtained by a student, each value separated by a space. The final line contains query_name, the name of a student to query.

Constraints

Output Format

Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.



# Solution:--


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()
    
    for key,value in students_marks.itmes():
        if query_name==key:
            sum=0
            count=0
            for i in value  :
                sum+=i
                count+=1
            average=sum/count
            print("{:.2f}".format(average))

##Single asterisk(*) as used in function declaration allows variable number of arguments passed from calling environment. Inside the function it behaves as a tuple.

Comments

Popular posts from this blog

XAMPP, SQL BASIC COMMANDS

The Minion Game Hackerrank Solution

Arrays - DS | HackerRank Solutions