[英]How to round inside a list using f string
I want to round some numbers inside of a list by using f-string, but it returns我想使用 f-string 舍入列表中的一些数字,但它返回
unsupported format string passed to list.__format__
This is my code这是我的代码
IS_gradebooks = [['ISOM2020', [59, 100, 80, 55, 95, 87, 95, 98, 74, 69, 92, 94, 75, 97, 43, 57]],
['ISOM3400', [98, 73, 45, 88, 72, 94, 82, 100, 89, 52]],
['ISOM3600', [24, 44, 100, 81, 91, 93, 87, 72, 55]],
['ISOM4200', [90, 56, 78, 67, 90, 93]]
]
bruh=IS_gradebooks
for i in range(len(bruh)):
a=sum(bruh[i][1])/len(bruh[i][1])
bruh[i][1]=a
print(f"{bruh:.2f}")
You can change the variable bruh[i][1]
to "{0:.2f}".format(a)
and print that variable inside the loop:您可以将变量
bruh[i][1]
更改为"{0:.2f}".format(a)
并在循环内打印该变量:
for i in range(len(bruh)):
a=sum(bruh[i][1])/len(bruh[i][1])
bruh[i][1]="{0:.2f}".format(a)
print(bruh[i])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.