In: Computer Science
Functions also introduce the concept of modularity, where a program can be broken up into multiple smaller pieces; each of these modules contains one or more functions that can be used to perform a small part of the overall task (and which can be reused by other programs). Python includes a large library of modules, each of which includes useful pre- written functions that programmers can use in their own programs with the use of an import statement.
1. Identify the name of the module and briefly summarize what general purpose it serves.
2. Select THREE functions from this module. List each function’s name and briefly describe what it does.
3. Give an example of a type of program (real or hypothetical) for which this module is either essential or extremely useful.
>>Answer
>.Given
The two other modules from the list on the "Python Standard Library" page are:
1. datetime:
Name of the module: datetime module
General purpose: This module supplies classes which contains information about date and time objects. It is used to manipulate dates and times.
Three functions:
datetime.now( ): It gives current date and time.
date.today( ): It gives the current date.
date.fromtimestamp(timestamp): This method converts timestamp into
date.
Example: All the information (files) in a computer system from the
moment it has been created is stored in the system along with its
timestamp, date and time. When this data needs to be manipulated by
developers, datetime module will be an absolute necessity.
2. cmath:
Name of the module: cmath module
General purpose: When dealing with complex numbers or floating point numbers, this module has all the useful methods to manipulate such types of numbers as arguements.
Three functions:
cmath.phase(x): This returns the phase of x as a float.It is
basically one of the ways to convert rectangualr coordinates to
polar coordinates.
cmath.exp(x): It retuens e to the power of x, where e is base of
natural logarithms.
cmath.sqrt(x): It gives the square root of x.
Example: With cmath python module, the half-life of an unkown
radioactive element by measuring the mass at an interval.