Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
import time import math def multiply(w, x, y, z): product = w * x * y * z product = float(product) return product def expCube(x): cubed = x * x * x cubed = float(cubed) return cubed def expSq(x): squared = x * x squared = float(squared) return squared def fraction(x, y): fract = x / y fract = float(fract) return fract def Lt(x, y): length = raw_input("What is the %s of the %s?" % (x, y)) length = float(length) return length def response(x, y): time.sleep(1) ans = "The volume of the %s is %d." % (x, y) return ans Sol = raw_input("Select which solid you want to calculate the volume of. You can choose 'Cube', 'Cylinder', 'Sphere', 'Cone', 'Pyramid', or 'Rectangular Prism'.") solid = Sol.lower() if solid == "cube": cubeSideLt = Lt("side length", "cube") volCube = expCube(cubeSideLt) print response("cube", volCube) elif solid == "cylinder": cylinRad = Lt("radius", "cylinder") cylinHt = Lt("height", "cylinder") volCylinder = multiply(math.pi, expSq(cylinRad), cylinHt, 1) print response("cylinder", volCylinder) elif solid == "sphere": sphereRad = Lt("radius", "sphere") volSphere = multiply(math.pi, expCube(sphereRad), fraction(4.0, 3.0), 1) print response("sphere", volSphere) elif solid == "cone": coneRad = Lt("radius", "cone") coneHt = Lt("height", "cone") volCone = multiply(math.pi, expSq(coneRad), coneHt, fraction(1.0, 3.0)) print response("cone", volCone) elif solid == "pyramid": pyraSideLt = Lt("length", "pyramid's base") pyraSideWth = Lt("width", "pyramid's base") pyraHt = Lt("height", "pyramid") volPyramid = multiply(pyraSideLt, pyraSideWth, pyraHt, fraction(1.0, 3.0)) print response("pyramid", volPyramid) elif solid == "rectangular prism": prismSideLt = Lt("length", "rectangular prism") prismSideWth = Lt("width", "rectangular prism") prismSideHt = Lt("height", "rectangular prism") volPrism = multiply(prismSideLt, prismSideWth, prismSideHt, 1) print response("rectangular prism", volPrism) else: print "Invalid Shape!!! It must be either 'Cube', 'Cylinder', 'Sphere', 'Cone', 'Pyramid', or 'Rectangular Prism'!"
ch_VolumeContCalc.py
( around 60 lines python code )
Published By:
EM5700
Published on
2019-10-09T02:32:19Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here