Volume calculator

tupac

Mohammad Alsuwaidi

Posted on December 14, 2021

Volume calculator

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()


Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
tupac
Mohammad Alsuwaidi

Posted on December 14, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Python For Beginners
python Python For Beginners

October 12, 2024

Data Types Part-05
python Data Types Part-05

August 29, 2024

The Tale of the Four Primal Forms
python The Tale of the Four Primal Forms

September 11, 2024

A Poetic Challenge !?
python A Poetic Challenge !?

September 17, 2024