-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathFunctionsLtP3.py
53 lines (37 loc) · 1.28 KB
/
MathFunctionsLtP3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# The math module imported
import math
# You can access the methods by referencing the module
# round up value
print("ceil(4.4) = ", math.ceil(4.4))
# round down value
print("floor(4.4) = ", math.floor(4.4))
# absolute value (without sign)
print("fabs(-4.4) = ", math.fabs(-4.4))
# Factorial = 1 * 2 * 3 * 4
print("factorial(4) = ", math.factorial(4))
# Return remainder of division
print("fmod(5,4) =", math.fmod(5 , 4))
# Receive a float and return an int
print("trunc(4.2) = ", math.trunc(4.2))
# Return a power of a number
print("pow(2,2) = ", math.pow(2, 2))
# Return the square root
print("sqrt(4) = ", math.sqrt(4))
# Special values
print("math.e = ", math.e)
print("math.pi = ", math.pi)
# Return e^x (exponent)
print("exp(4) = ", math.exp(4))
# Return the natural logarithm e * e * e ~= 20 so log(20) tells
# you that e^3 ~= 20
print("log(20) = ", math.log(20))
# You can define the base and 10^3 - 1000
print("log(1000,10) = ", math.log(1000,10))
# You can also use base 10 like this
print("log(1000,10) = ", math.log10(1000))
# We have the following trig functions
# sin, cos, tan, asin, acos, atan, atan2, asinh, acosh,
# atanh, sinh, cosh, tanh
# Convert radians to degrees and vice versa
print("degrees(1.5708) = ", math.degrees(1.5708))
print("radians(90", math.radians(90))