Source code for area_volume
"""
Prints the area and volume of a cylinder. This module is used to illustrate
the use of functions and how some functions return values and how others
return nothing.
Note that function ``area_and_volume`` does not return a value. As such
it returns the special value ``None``.
Example use of these functions::
>>> print area_circle(5)
>>> vc = volume_cylinder(5,10)
>>> print "Volume of cylinder is", vc
>>> area_and_volume(5,10)
"""
[docs]def area_circle(radius):
""" Returns the area of a circle given the radius. """
pi = 3.14159
return pi * radius ** 2
[docs]def volume_cylinder(radius,height):
""" Returns the volume of a cylinder given radius and height. """
pi = 3.14159
area = area_circle(radius)
return area * height
[docs]def area_cylinder(radius,height):
""" Returns the surface area of a cylinder given radius and height. """
pi = 3.14159
circle_area = area_circle(radius)
height_area = 2 * radius * pi * height
return 2*circle_area + height_area
[docs]def area_and_volume(radius, height):
"""
Prints the area and volume of a cylinder given radius and height.
The function returns nothing, i.e. None.
"""
print "For a cylinder with radius", radius, "and height", height
print "The surface area is ", area_cylinder(radius,height)
print "The volume is ", volume_cylinder(radius, height)