floating point - How to format a long variable to use commas in python -


hi format variable volume before printed below, cant seem find tut 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 sphere (the earth) \nvolume = ( 4 / 3 ) * pi * radius ** 3")     print ("radius = ", radius, "kms")     print ("the volume of earth = ", volume, "kms3\n\n")   volume_sphere(6371) 

this fixed formatting.

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

enjoy!!!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -