Write a program to Python Program to Calculate Area & Volume of Sphere

Here is a Python program that calculates the area and volume of a sphere given the radius of the sphere:

Python Program to Calculate Area & Volume of Sphere

This program first imports the math module, which provides mathematical functions such as pi. It then defines two functions: sphere_area and sphere_volume, which calculates the surface area and volume of a sphere, respectively. These functions take the radius of the sphere as an argument and use it to compute the area and volume using the formulas for the surface area and volume of a sphere.

import math

def sphere_area(radius):
  return 4 * math.pi * radius**2

def sphere_volume(radius):
  return (4/3) * math.pi * radius**3

radius = float(input("Enter the radius of the sphere: "))

area = sphere_area(radius)
volume = sphere_volume(radius)

print("The area of the sphere is:", area)
print("The volume of the sphere is:", volume)

 

Here is the output of the python Program:-

Enter radius of circle: 5
Area = 314.1593.
Volume = 523.5988.

The program then reads the radius of the sphere from the user and calculates the area and volume using the sphere_area and sphere_volume functions. Finally, it prints the results to the console.

Leave a Comment

Verified by MonsterInsights