Here are the Python programs to calculate Volume of a Sphere and Cone:

Sphere Volume

python

import math

def volume_of_sphere(radius):
    volume = (4/3) * math.pi * radius ** 3
    return round(volume, 2)

radius = float(input("Enter the radius of the sphere: "))
print(f"Volume of sphere = {volume_of_sphere(radius)} cubic units")

Cone Volume

python

import math

def volume_of_cone(radius, height):
    volume = (1/3) * math.pi * radius ** 2 * height
    return round(volume, 2)

radius = float(input("Enter the radius of the cone's base: "))
height = float(input("Enter the height of the cone: "))
print(f"Volume of cone = {volume_of_cone(radius, height)} cubic units")

Combined Program

python

import math

def volume_of_sphere(radius):
    return round((4/3) * math.pi * radius ** 3, 2)

def volume_of_cone(radius, height):
    return round((1/3) * math.pi * radius ** 2 * height, 2)

# Sphere
r = float(input("Sphere — Enter radius: "))
print(f"Volume of Sphere: {volume_of_sphere(r)} cubic units")

# Cone
r = float(input("\nCone — Enter radius: "))
h = float(input("Cone — Enter height: "))
print(f"Volume of Cone: {volume_of_cone(r, h)} cubic units")

Key formulas used:

ShapeFormula
SphereV = (4/3) × π × r³
ConeV = (1/3) × π × r² × h

math.pi gives Python’s built-in value of π ≈ 3.14159…, and ** is the exponentiation operator. You can drag the sliders in the calculator above to explore how volume changes with different dimensions.

Here are the Python programs to calculate Volume of a Sphere and Cone:

Sphere Volume

python

import math

def volume_of_sphere(radius):
    volume = (4/3) * math.pi * radius ** 3
    return round(volume, 2)

radius = float(input("Enter the radius of the sphere: "))
print(f"Volume of sphere = {volume_of_sphere(radius)} cubic units")

Cone Volume

python

import math

def volume_of_cone(radius, height):
    volume = (1/3) * math.pi * radius ** 2 * height
    return round(volume, 2)

radius = float(input("Enter the radius of the cone's base: "))
height = float(input("Enter the height of the cone: "))
print(f"Volume of cone = {volume_of_cone(radius, height)} cubic units")

Combined Program

python

import math

def volume_of_sphere(radius):
    return round((4/3) * math.pi * radius ** 3, 2)

def volume_of_cone(radius, height):
    return round((1/3) * math.pi * radius ** 2 * height, 2)

# Sphere
r = float(input("Sphere — Enter radius: "))
print(f"Volume of Sphere: {volume_of_sphere(r)} cubic units")

# Cone
r = float(input("\nCone — Enter radius: "))
h = float(input("Cone — Enter height: "))
print(f"Volume of Cone: {volume_of_cone(r, h)} cubic units")

Key formulas used:

ShapeFormula
SphereV = (4/3) × π × r³
ConeV = (1/3) × π × r² × h

math.pi gives Python’s built-in value of π ≈ 3.14159…, and ** is the exponentiation operator. You can drag the sliders in the calculator above to explore how volume changes with different dimensions.