Вы находитесь на странице: 1из 5

MATH MODULE

The Math module in the Python standard library contains several


functions that are useful for performing mathematical operation.
These functions typically accept one or more values as arguments,
perform a mathematical operation using the arguments, and return
the result.
Code:
import math

def main();
a = float(input(Enter the length of side A: ))
b = float(input(Enter the length of side B: ))

c = math.hypot(a, b)
print The length of the hypotenuse is , c
Output:
Enter the length of side A: 3
Enter the length of side B: 6
The length of the hypotenuse is 6.7082039325
>>>

MODULE
A module is a single text file that contains a related collection of
variables, functions, and other objects.
math Module Function Description

acos(x) Returns the arc cosine of x, in radians.


asin(x) Returns the arc sine of x, in radians.
atan(x) Returns the arc tangent of x, in radians.
ceil(x) Returns the smallest integer that is greater than or equal to x.
cos(x) Returns the cosine of x in radians.
degrees(x) Assuming x is an angle in radians, the function returns the
angle converted to degrees.
exp(x) Returns e
floor(x) Returns the largest that is less than or equal to x.
hypot(x, y) Returns the length of a hypotenuse from (0,0) to (x,y).
log(x) Returns the natural logarithm of x.
log10(x) Returns the base-10 logarithm of x.
radians(x) Assuming x is an angle in degrees, the function returns the
angle converted to radians.
sin(x) Returns the sine of x in radians.
sqrt(x) Returns the square root of x.
tan(x) Returns the tangent of x in radians.
#! /usr/local/bin/python 1 1. We can add a Unix shebang line if were going to
run the module as a program rather than import it
*This is a test module 2 into other modules.
2. This string literal is the documentation string. It
import sys
import math
3 describes the modules purpose and functionality.
3. These statements load other modules whose
var1 = mimetic
var2 = 3.14159 4 functions or objects are required to run the code in
the current module.
class A: 4. These statements are the modules global
This is class A variables and initialization code. These names can
class B:
5 be used by functions and classes within this
This is class B module and by programs that import this module.
pass 5. These statements are this modules class
definitions;
def func1():
This is function func1 6. These statements are this modules function
pass 6 definitions;
7. When the module code runs, this if statement
def func2(); checks whether this module is running as a
if __name__ == __main__: 7 program or has benn imported as a module.
pass ________________
Documenting Module
A modules docstring should comprehensively describe the modules
purpose and functionality and should be more elaborate than a function
docstring. Docstrings are assigned to the modules _doc_attribute and,
unlike # comments, can be accessed with the dot operator at run time.

>>> import circle


>>> import circle.__doc__
None
>>> import random
>>> import random.__doc__
Random variable generators.

Вам также может понравиться