84.2k views
2 votes
Write a Python function to determine the volume of material remaining after the hole is drilled. The function should take as input parameters the length, width and height of the box and the radius of the hole. (You may assume that the measurements are all specified in the same length units.) The function should return the volume of material remaining. The function should check that the dimensions are consistent with reality. For example, the radius of the hole should be less than the minimum of (length/2) and (width/2). If the input data is not consistent, the function should return an appropriate value or otherwise indicate the problem. (It is your choice as to how to handle this. You may want to consider explaining your method for error handling in a docstring.)

1 Answer

3 votes

Answer:

height = int(input ("Enter height : ") )

print (height)

width = int( input("Enter length : ") )

print (width)

half_width =width/2

half_height=height/2

while 0==0:

radius = float( input("Enter radius : ") )

print (radius)

if radius<half_width and radius <half_height:

break

def remainingVolume(height,width,radius):

vol_box=height*width*width

print (vol_box)

vol_hole=3.14178*radius*radius*height

print (vol_hole)

remaining_vol=vol_box-vol_hole

print ("Remaining volume is ",remaining_vol)

remainingVolume(height,width,radius);

Step-by-step explanation:

Take input from user for height ,width and radius. To find volume of box formula is
vol=height* width*length\\

Let's assume width and length is same so

length= width

Using this formula of box volume find box volume.Now find volume of hole.

Consider hole as small cylinder, find volume of cylinder and subtract from volume of box to get remaining volume of box after hole.


vol_of_cyl=\pi radius^(2) height

User Ascanio
by
7.9k points