Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Hakkerank problem I can't solve ayo Unladen Swallow Posts: 1 Threads: 1 Joined: Aug 2019 Reputation: 0 Likes received: 0 #1 Aug-29-2019, 05:04 AM 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)))) ``` ThomasL Minister of Silly Walks Posts: 351 Threads: 4 Joined: Jun 2019 Reputation: 62 Likes received: 82 #2 Aug-29-2019, 11:18 AM Please show us what your code outputs and what you expect it to output I ran your code and besides you shouldn´t name a variable "sum" as this is a python function it works for me « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Formulae to solve problem BigDisAok 3 722 Jun-26-2018, 03:07 PM Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)