Round to 2 decimal places

nick martinez nick.martinez2 at aol.com
Wed Dec 6 19:58:00 EST 2017


I'm stuck. I need my program to round the end solution to 2 decimal places but cant figure it out. Can someone help? I've been trying between printf and round() but cant seem to get either to work. Python 3.5 is what I'm using.
import math

print("This program will calculate the surface area and volume of a 3-dimensional cone: ")
print()
print()
r = input("What is the radius in feet? (no negatives): ")
h = input("What is the height in feet? (no negatives): ")
r = float(r)
h = float(h)
if r > 0 and h > 0:
    
   surfacearea = math.pi*r**2+r*math.pi*(math.sqrt(r**2+h**2))
   volume = (1/3)*math.pi*r**2*h



   print()
   print("Your Answer is:")
   print()

   print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", volume, "\nand surface area of : ", surfacearea,)
else:
    print("No negatives allowed, try again.")



More information about the Python-list mailing list