We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Finding the percentage
Finding the percentage
Sort by
recency
|
3838 Discussions
|
Please Login in order to post a comment
Python 1 line solution using list comprehension :
print(f"{sum(x for x in student_marks[query_name])/3:.2f}")
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()
print(f"{average:.2f}")
print(f"{sum(student_marks[query_name])/3:.2f}")
length 3 is fixed. You could just hard code it.
this is how i did it :)
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() addition = 0 for i in student_marks[query_name]: addition = addition + i average_Score = addition/3 print ('{:.2f}'.format(average_Score))
Try this