小编Shi*_*iuu的帖子

Not able to print with two decimals

I am solving a problem in hackerrank , and i cannot print a output with two decimal places.

I have tried round(number,2) and -

avg=(toavg[0]+toavg[1]+toavg[2])/3
print(float("{0:.2f}".format((toavg[0]+toavg[1]+toavg[2])/3)))
Run Code Online (Sandbox Code Playgroud)

I am using python 3.

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()
    toavg=student_marks[query_name]
    avg=(toavg[0]+toavg[1]+toavg[2])/3
    print(float("{0:.2f}".format((toavg[0]+toavg[1]+toavg[2])/3)))
Run Code Online (Sandbox Code Playgroud)

I expected 56.00 or 36.50 but i got 56.0 or 36.5.

python

-2
推荐指数
1
解决办法
32
查看次数

标签 统计

python ×1