我的输出是:“”2.4 Z_0玻色子的半衰期:(4.203e-35 +/- 5.571e-37)秒“” 虽然我希望它给我(“ Z_0 玻色子的半衰期:(4.203 +/- 0.056)e-35 秒)或类似的东西。 我该怎么做?
print(f"2.4 Half-life of Z_0 boson: \
({half_life_Z_0_boson:.3e} +/- {error_half_life:.3e}) seconds\n")
我尝试以不同的方式格式化...它只是不起作用。
这对我有用:
half_life_Z_0_boson = str(half_life_Z_0_boson).split('e')
half_life_Z_0_boson = [float(half_life_Z_0_boson[0]), int(half_life_Z_0_boson[1])]
print(f"2.4 Half-life of Z_0 boson: \
({half_life_Z_0_boson[0]} +/- {error_half_life/10**(half_life_Z_0_boson[1]):.2})e{half_life_Z_0_boson[1]} seconds\n")
它并不漂亮,但请告诉我这是否解决了您的问题。