Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerRank Finding the percentage solution in python

YASH PAL, 31 July 2024

In this HackerRank Finding the percentage problem solution in python, 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.

HackerRank Finding the percentage solution in python

Problem solution in Python 2 programming.

n=int(raw_input())

dic={}

for i in range(n):
	line=raw_input().split()
	dic[line[0]]=sum(map(float,line[1:]))/3.0

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
d={}
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))

coding problems solutions Hackerrank Problems Solutions Python Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes