By completing this challenge we are going to learn how to define our own functions in Python.
We will also assign arguments to our functions.
Look at the code below used to calculate the volume of a cube. This code is based on the use of a function called getVolumeOfCube(). This function takes one argument (width) and return the volume of the cube (in mL).
def getVolumeOfCube(width): volume = width * width * width #This calculates the volume in cubic millimeters. Divide it by 1000 to get this volume in mL volume=volume/1000 return volume #Main Program Starts Here cubeVolume=getVolumeOfCube(50) print("The volume of a cube with a side of 50mm is: " + str(cubeVolume) + " mL.")
Complete the following code to add 3 functions as follows:
- getVolumeOfCylinder(radius, height)
- getVolumeOfCuboid(width, length, height)
- getVolumeOfCone(radius, height)
Use all of your functions to calculate the volume of each of these bottles: