HackerRankInterview QuestionsPythonPython InterviewRandom

HackerRank Finding the percentage solution in python | hacker rank interview Question solution

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.


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.


Output Format

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

Sample Input 0

Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60

Sample Output 0


Explanation 0

Marks for Malika are  whose average is 

Sample Input 1

Harsh 25 26.5 28
Anurag 26 28 30

Sample Output 1

In this HackerRank Finding the percentage problem solution in python, we need to develop a python program that can read a dictionary that contains the key-value pairs of name and marks list of students. and we need to print the average of marks of every student on the output screen. 

Problem solution in Python 2 programming.



for i in range(n):

print '%.2f' % dic[raw_input()]

Problem solution in Python 3 programming.

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()

if query_name in student_marks:
x = ((float(student_marks[query_name][0]) + float(student_marks[query_name][1]) + float(student_marks[query_name][2])) / 3)

print('%.2f' % x)

Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
for _ in range(int(raw_input())):
item = raw_input().split()
name = item[0]
grade = [float(a) for a in item[1:]]
d[name] = grade
request = raw_input().strip()

avg = reduce(lambda x, y: x + y, d[request])/len(d[request])
print '%.2f' %(avg)

Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

n = int(input())

c = 1
students = {}
while c <= n :
line = input()
inList = line.split()
students[inList[0]] = inList[1:4]
c += 1

student = input()

sum = 0
for gs in students[student]:
sum = sum + float(gs)

print('{0:.2f}'.format(sum / 3))

Leave a Reply

10 Best Artificial Intelligence Software|artificial intelligence tools 5 nft games to earn money | Best NFT games for earn crypto Earn Money From Minting NFTs| How to mint NFT for free Top 10 Things You Need To Know About Python List | python lists functions 10 Popular PHP frameworks for web developers| best php frameworks 12 Tips On How To Become a Python Developer | python For beginner 12 Best Nodejs Frameworks for App Development in 2022 how to create google web stories, Steps to create web stories Top 10 Features in Angular 13 Every Developer Should Know | Angular 13 Features 10 Best Angular UI Libraries | angular ui components | angular Project 10 Best Web Development Frameworks in 2022 Frontend & Backend 18 Best Open-Source and Free Database Software | best database software for beginners Top 10+ Best Java IDEs & Online Java Compilers | best java ide for beginners top 10 besic to andvance java books |java books for beginer Top 5 Themes For Blogger, professional blogger theme download BEST Python Courses Online,Top 10 Courses to Learn Python in 2022 Top 13 python libraries for data science