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
  • 52,115
  • 13
  • 74
  • 94
Universe A7
  • 133
  • 4

2 Answers2

2

You can format your float like this:

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

or

>>> "%.2f" % 56.0
'56.00'
Jarvis
  • 8,331
  • 3
  • 26
  • 54
1

You can change the line

print(round(ans),2)

to

print("{:.2f}".format(round(a, 2)))
Dharman
  • 26,923
  • 21
  • 73
  • 125
Chirag
  • 46
  • 5