0

Expected output: 56.00 and my output: 56.0

from statistics import mean
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_list=list(student_marks[query_name])
    ans=(mean(marks_list))
    print(round(ans),2)
 

My answer is 56.0 for the input, so is there any short way to do this?

khelwood
  • 55,782
  • 14
  • 81
  • 108
Universe A7
  • 126
  • 7

2 Answers2

2

You can format your float like this:

>>> "{:.2f}".format(56.0)
'56.00'

or

>>> "%.2f" % 56.0
'56.00'
Jarvis
  • 8,494
  • 3
  • 27
  • 58
1

You can change the line

print(round(ans),2)

to

print("{:.2f}".format(round(a, 2)))
Dharman
  • 30,962
  • 25
  • 85
  • 135
Chirag
  • 46
  • 5