Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone.
In this file there should be four methods defined.
Now Write a Python program named LastNameMenu that asks the user to find volumes of 3D objects. The program will then present the following menu of selections:
Here are the formula used for volume calculation:
Volume of a cube with side a = a3
Volume of a sphere with radius r =4/3 π r3
Volume of a cylinder with radius r and height h = π r2 h
Volume of a cone with radius r and height h = 1/3 π r2 h
Here is an example session with the program, using console input. The user’s input is shown in bold.
MENU
Enter your choice: 1 [Enter]
We are going to calculate the volume of a cube.
Please enter the side of a cube in inches: 10 [Enter]
Volume of the cube with side 10 inches is: 1000.00 cubic inches.
MENU
Enter your choice: 3 [Enter]
We are going to calculate the volume of a cylinder.
Please enter the radius of a cylinder in inches: 2.5 [Enter]
Please enter the height of a cylinder in inches: 6 [Enter]
Volume of the Cylinder with radius 2.5 inches and height 6 inches is: 117.81 cubic inches.
MENU
Enter your choice: 5 [Enter]
Bye!
THIS IS THE CODE OF THE FILE LastNameMenu.py .
from lastNameVolumes import *
def menuFirstName():
print("MENU\n")
print("Volume of a cube in cubic inches.\n")
print("Volume of a sphere in cubic inches.\n")
print("Volume of a cylinder in cubic inches.\n")
print("Volume of a cone in cubic inches.\n")
print("Exit the program\n")
def validate(r,h):
if r>0 and h>0:
return True
else:
return False
def validate2(s):
if s>0:
return True
else:
return False
menuFirstName()
while True:
a=int(input("Enter your choice:\n"))
if a==1:
print("We are going to calculate the volume of a cube.\n")
b=float(input("Please enter the side of a cube in inches:\n"))
c=validate2(b)
if c==1:
e=cubeVolFirstName(b)
print("Volume of the cube with side " + str(b) + " inches is: " + str(e) + " cubic inches.\n")
menuFirstName()
elif a==2:
print("We are going to calculate the volume of a sphere.\n")
b=float(input("Please enter the radius of a sphere in inches:\n"))
c=validate2(b)
if c==1:
print("Volume of the sphere with radius " + str(b) + " inches is: " + str(sphereVolFirstName(b)) + " cubic inches.\n")
menuFirstName()
elif a==3:
print("We are going to calculate the volume of a cylinder.\n")
b=float(input("Please enter the radius of a cylinder in inches:\n"))
d=float(input("Please enter the height of a cylinder in inches:\n"))
c=validate(b,d)
if c==1:
print("Volume of the cylinder with radius " + str(b) + "and height " + str(d) + "inches is: " + str(cylVolFirstName(b,d)) + " cubic inches.\n")
menuFirstName()
elif a==4:
print("We are going to calculate the volume of a cone.\n")
b=float(input("Please enter the radius of a cone in inches:\n"))
d=float(input("Please enter the height of a cone in inches:\n"))
c=validate(b,d)
if c==1:
print("Volume of the cone with radius " + str(b) + " and height " + str(d) + " inches is: " + str(coneVolFirstName(b,d)) + " cubic inches.\n")
menuFirstName()
elif a==5:
print("Bye!")
exit()
else:
print("ERROR !!! Enter correct value\n")
menuFirstName()
THIS IS THE CODE OF THE FILE lastNameVolumes.py
def cubeVolFirstName(side):
return round((side*side*side),2)
def sphereVolFirstName(radius):
return round(((4*3.14*radius*radius*radius)/3),2)
def cylVolFirstName(radius,height):
return round((3.14*radius*radius*height),2)
def coneVolFirstName(radius,height):
return round(((3.14*radius*radius*height)/3),2)
HOPE IT HELPS YOU :)
Get Answers For Free
Most questions answered within 1 hours.