题解 | 学生基本信息输入输出
from decimal import Decimal, ROUND_HALF_UP n, score = input().split(";") s = score.split(",") def round_correct(num): return Decimal(str(num)).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP) print( f"The each subject score of No. {n} is {round_correct(s[0])}, {round_correct(s[1])}, {round_correct(s[2])}." )
使用 decimal
模块中的 Decimal
类,可以更精确地控制四舍五入行为