-2

Hi i would like to format the variable volume before it is printed as so below, i cant seem to find a tut that helps correctly.

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)
Shawn
  • 47,241
  • 3
  • 26
  • 60
Goulouh Anwar
  • 737
  • 1
  • 11
  • 21

1 Answers1

1

This fixed the formatting.

print ("The volume of the earth = ", '{:20,.2f}'.format(volume), "Kms3\n\n")

Enjoy!!!

Goulouh Anwar
  • 737
  • 1
  • 11
  • 21