You have a record of students. Each record contains the student's name, and their percent marks in Maths, Physics and Chemistry. The marks can be floating values. The user enters some integer followed by the names and marks for students.
You are required to save the record in a dictionary data type. The user then enters a student's name. Output the average percentage marks obtained by that student, correct to two decimal places.
Input Format
The first line contains the integer , the number of students. The next lines contains the name and marks obtained by that student separated by a space. The final line contains the name of a particular student previously listed.
Constraints
Output Format
Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.
Sample Input 0
3
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika
Sample Output 0
56.00
Explanation 0
Marks for Malika are whose average is
Sample Input 1
2
Harsh 25 26.5 28
Anurag 26 28 30
Harsh
Sample Output 1
26.50
Finding the percentage - Hacker Rank Solution
Use a dictionary to store the averages as
values
and the name as keys
.
Problem Tester's code:
d={}
for i in range(int(raw_input())):
line=raw_input().split()
d[line[0]]=sum(map(float,line[1:]))/3
print '%.2f' % d[raw_input()]
Plz explain why float is used ? There should be a function
ReplyDeleteRwad the question its telling to display decimal upto 2 decimal places for which we have to use float data type for the case
Deletewhy I'm getting error for print can u please tell me what is the reason of that
ReplyDeleteuse () this
Deletebecuz youre noob
Deletelol dont acts like a smart
Deleten = int(input())
ReplyDeletestudent_marks = {}
for _ in range(n):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
l=list(student_marks[query_name])
length=len(l)
s=sum(l)
average=s/length
print('%.2f'%average)
for i in range(int(raw_input())):
ReplyDeleteNameError: name 'raw_input' is not defined
this error is show when i run above code anyone help me give me correct code
Try only (int(input()))
Delete