This Python program calculates the volume and surface area of a sphere.
The user is prompted to enter the radius, and the program uses mathematical formulas to compute and display the results.
The code is formatted for seamless integration into a webpage using the specified HTML structure.
import math
radius = float(input("Please enter the radius of the sphere: "))
volume = (4/3) * math.pi * radius ** 3
surface_area = 4 * math.pi * radius ** 2
print("The volume of the sphere is:", volume)
print("The surface area of the sphere is:", surface_area)
Please enter the radius of the sphere: 2
The volume of the sphere is: 33.510321638291124
The surface area of the sphere is: 50.26548245743669
Here’s how the program works:
- It uses the math
module to access the constant pi
- The volume is calculated using the formula (4/3) × π × radius³
- The surface area is calculated using 4 × π × radius²
- The results are printed using the print()
function