Finding the percentage
Finding the percentage
+ 0 comments 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() marks = student_marks.get(query_name) sumofmarks=sum(marks) avg=sumofmarks/len(marks) print('%.2f' % avg)
+ 0 comments There's probably a simpler way to do this but this is what worked for me:
def find_avg(name, student_marks): for key in student_marks: if key == name: records = student_marks[key] import statistics average = statistics.mean(records) return average 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() avg = find_avg(query_name, student_marks) print('%.2f' % avg)
+ 0 comments 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()
avg = [sum(student_marks[name])/len(student_marks[name]) for name in student_marks.keys() if name == query_name] print("{:.2f}".format(avg[0]))
+ 2 comments average = "{:.2f}".format(average) can anyone explain above line..?
+ 0 comments why do i get runtime error for test cases 1 and 3 only?
Sort 3342 Discussions, By:
Please Login in order to post a comment