嗨我想在打印之前格式化变量,如下所示,我似乎无法找到一个有助于正确的啧啧。
def volume_sphere(radius):
"""radius = 12,742 / 2 (earth diameter)"""
pi = 3.141592653589
volume = ( 4 / 3 ) * pi * radius ** 3
format('{:20,.2f}'.format(volume))
# volume format 0,000,000,000,000,000,000
print ("Calculate volume of a sphere (The Earth) \nvolume = ( 4 / 3 ) * pi * radius ** 3")
print ("Radius = ", radius, "Kms")
print ("The volume of the earth = ", volume, "Kms3\n\n")
volume_sphere(6371)
答案 0 :(得分:1)
这修复了格式化问题。
print ("The volume of the earth = ", '{:20,.2f}'.format(volume), "Kms3\n\n")
享受!!!