Python Forum
Hakkerank problem I can't solve
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hakkerank problem I can't solve
#1
I attempted a python task on Hackerrank, but my code seems to have a problem I can't fix. The first input is for the number of students, the second set for the name of the student(s) and the marks of 3 subjects. The third input is for the student whose marks the code is supposed to calculate the average of. My code does not accurately match the scores of the last input with the corresponding scores in the second input. Someone pls help me. I can't figure out the problem.

n = int(input()) # first input
sum = 0
scores_needed = 0
student_marks = {}
for i in range(n):
    line = input().split() # second set of input
    name = line[0]
    scores = line[1:]
    student_marks[name] = scores
query_name = input() # third input
for i in student_marks:# this for loop is the part of the code causing issue(s)
    print(i)
    if query_name == i:
        scores_needed = student_marks.get(query_name)
for score in scores_needed:
    sum += float(score)
print("{:.2f}".format(float(sum / len(scores_needed))))
Reply


Messages In This Thread
Hakkerank problem I can't solve - by ayo - Aug-29-2019, 05:04 AM
RE: Hakkerank problem I can't solve - by ThomasL - Aug-29-2019, 11:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can someone help me solve this programming problem? SuchUmami 6 909 Nov-20-2023, 10:01 AM
Last Post: EdwardMatthew
  A simple problem, how best to solve it? SuchUmami 2 723 Sep-01-2023, 05:36 AM
Last Post: Pedroski55
  How to solve this simple problem? Check if cvs first element is the same in each row? thesquid 2 1,232 Jun-14-2022, 08:35 PM
Last Post: thesquid
  How do I solve the second problem? Cranberry 1 1,135 May-16-2022, 11:56 AM
Last Post: Larz60+
  Try to solve GTG multiplication table problem. Frankduc 6 2,013 Jan-18-2022, 08:26 PM
Last Post: Frankduc
  Sudoku Solver, please help to solve a problem. AdithyaR 5 2,118 Oct-28-2021, 03:15 PM
Last Post: deanhystad
  General list size question to solve problem Milfredo 3 2,357 Sep-27-2020, 08:42 AM
Last Post: Milfredo
  I want to solve the following problem srisrinu 4 5,959 May-09-2020, 01:07 PM
Last Post: Larz60+
  Solve Pynput Problem when changing language? ppel123 0 2,279 Feb-19-2020, 03:38 PM
Last Post: ppel123
  Formulae to solve problem BigDisAok 3 2,999 Jun-26-2018, 03:07 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020