Python - Surface Area of a Sphere

by matt392 in Circuits > Software

57 Views, 0 Favorites, 0 Comments

Python - Surface Area of a Sphere

surfaceareasphere.jpg
# import the math module for the pi constant
import math

print ("This program will calculate surface area of a sphere")

#  Formula for surface area of a sphere is: surface area = 4 * pi * (r**2)
#  pi is a constant: 3.14159265359

#  Function to solve for surface area

def solveForSurfaceArea():
    print ("Solving for Surface Area")
    radius = int(input("Please enter the radius: ") )
    surfaceArea = 4 * math.pi * (radius**2)
    print("The surface area is:", surfaceArea)
    
continueCalculations = "y"

# Check to see if the user wants to continue to calculate Surface Area of a sphere
while (continueCalculations=="y"):
    solveForSurfaceArea()
    continueCalculations = input("Would like to do another calculation for the Surface Area of a sphere? (y/n): ")