Do calculation with math module
Do calculation with math module
import math# from w w w . ja v a 2 s.c o m
print math.cos(math.pi / 4.0)
print math.pi, math.e
print math.log(1024, 2)
print abs(-42), 2**4, pow(2, 4)
print math.sin(2 * math.pi / 180)
print math.sqrt(144), math.sqrt(2) # Square root
print int(2.567), round(2.567), round(2.567, 2) # Truncate, round
x = 2.5
print math.floor(x)
print math.ceil(x)
print math.sqrt(x)
print math.frexp(x)
print math.modf(x)
The code above generates the following result.