0

I'm learning Python at the moment and I solved some easy coding challenges on hackerrank.com. But I don't know how to solve this one... The answer is right, but my result is for example 65.0 but hackerrank wants it to be 65.00... How can I add the second decimal number?

n = int(input())
student_marks = {}
for _ in range(n):
    name, *grades = input().split()
    scores = list(map(float, grades))
    student_marks[name] = scores

query_name = input()
average = (student_marks[query_name][0] + student_marks[query_name][1] + student_marks[query_name][2]) / 3

print(average)
Kevin
  • 74,910
  • 12
  • 133
  • 166
itsame
  • 171
  • 4
  • 14

1 Answers1

1

Using f-strings:

value =6.1
print(f'{value:.2f}')

Using format:

print("{:.2f}".format(value))
Christian Sloper
  • 7,440
  • 3
  • 15
  • 28