Volume calculator
Tags: python, beginners, programming, tutorial
Published: 2021-12-14 06:13:18

i made a shape volume calculator tell me if i can improve it even more

```
# this is volume calculator according to calculator.net
import sys
from math import sqrt

shape = float(input(
    "Enter 1 for sphere, 2 for cone, 3 for cube, 4 for cylinder, 5 for Rectangular Tank, 6 for Capsule, \
7 for Conical Frustum, 8 for Ellipsoid, 9 "
    "for Square Pyramid, 10 for Tube, 11 for Spherical Cap: "))

if shape == 1:
    r = int(input("enter the radius of the sphere: "))
    an = 1.33333333333 * 3.141592653589793 * r ** 3
    unit = raw_input("Enter the unit: ")
    print an, unit, "^3"
elif shape == 2:
    r = int(input("Enter the base radius : "))
    h = int(input("Enter the height of the cone: "))
    an = 0.33333333333 * 3.141592653589793 * r ** 2 * h
    unit = raw_input("Enter the unit: ")
    print an, unit, "^3"
elif shape == 3:
    l = int(input("Enter the length of one edge: "))
    an = l ** 3
    unit = raw_input("Enter the unit: ")
    print an, unit, "^3"
elif shape == 4:
    r = float(input("Enter the base radius: "))
    h = float(input("Enter the height of the cylinder: "))
    an = 3.141592653589793 * r ** 2 * h
    unit = raw_input("Enter the unit: ")
    print an, unit, "^3"
elif shape == 5:
    l = int(input("Enter the length of Rectangular Tank: "))
    w = int(input("Enter the width of Rectangular Tank: "))
    h = int(input("Enter the height of Rectangular Tank: "))
    an = l * w * h
    unit = raw_input("Enter the unit: ")
    print an, unit, "^3"
elif shape == 6:
    r = int(input("Enter the base radius: "))
    h = int(input("Enter the height: "))
    unit = raw_input("Enter the unit: ")
    an = 1.33333333333 * 3.141592653589793 * r ** 3 + 3.141592653589793 * r ** 2 * h
    print an, unit, "^3"
elif shape == 7:
    r = int(input("Enter Top Radius: "))
    b = int(input("Enter Bottom Radius: "))
    h = int(input("Enter height: "))
    unit = raw_input("Enter the unit: ")
    an = 0.33333333333 * 3.141592653589793 * h * (r ** 2 + r * b + b ** 2)
    print an, unit, "^3"
elif shape == 8:
    a1 = int(input("Enter the first axis: "))
    a2 = int(input("Enter the second axis: "))
    a3 = int(input("Enter the third axis: "))
    unit = raw_input("Enter the unit: ")
    an = 1.33333333333 * 3.141592653589793 * a1 * a2 * a3
    print an, unit, "^3"
elif shape == 9:
    b = int(input("Enter the Base Edge: "))
    h = int(input("Enter the Height: "))
    unit = raw_input("Enter the unit: ")
    an = 0.33333333333 * 3.141592653589793 * b ** 2 * h
    print an, unit, "^3"
elif shape == 10:
    d1 = int(input("Enter the outer diameter: "))
    d2 = int(input("Enter the inner diameter: "))
    l = int(input("Enter the length of tube: "))
    unit = raw_input("Enter the unit: ")
    an = 3.141592653589793 * (d1 ** 2 - d2 ** 2) / 4 * l
    print an, unit, "^3"
elif shape == 11:
    RR = int(input("Enter 1 if u have base radius or 2 if u have ball radius: "))
    if RR == 1:
        r = int(input("Enter the Base radius: "))
        h = int(input("Enter the Height: "))
        unit = raw_input("Enter the unit: ")
        R = (h ** 2.0 + r ** 2.0) / (2.0 * h)
        an = 0.33333333333 * 3.141592653589793 * h ** 2 * (3 * R - h)
        print an, unit, "^3"
    elif RR == 2:
        R = int(input("Enter the ball radius: "))
        h = int(input("Enter the Height: "))
        r = sqrt(2 * R * h - h ** 2)
        unit = raw_input("Enter the unit: ")
        an = 0.33333333333 * 3.141592653589793 * h ** 2 * (3 * R - h)
        print an, unit, "^3"
else:
    sys.exit()


```