EN
Python - math.exp() method example
0 points
math.exp()
is a method that takes only one parameter and returns exponential function value in the range 0
(exclusive) to infinity
.
xxxxxxxxxx
1
import math
2
3
print(math.exp(-100)) # 3.720075976020836E-44
4
print(math.exp(-1)) # 0.36787944117144233
5
print(math.exp(0)) # 1
6
print(math.exp(1)) # 2.718281828459045
7
print(math.exp(100)) # 2.6881171418161356E43
8
9
print(math.exp(-math.inf)) # 0
10
print(math.exp(math.inf)) # ∞ / +Infinity
11
print(math.exp(math.nan)) # NaN
Syntax |
xxxxxxxxxx 1 math.exp(number) |
Parameters | number - value that specifies the exponent |
Result |
Exponential function value of a number in the range If the value can not be calculated |
Description |
|
xxxxxxxxxx
1
import math
2
3
4
def print_line(y1, y2, dy, character):
5
line = ""
6
7
y = y1
8
while y < y2:
9
line += " "
10
y += dy
11
12
print(line, character)
13
14
15
x1 = -4
16
x2 = 2.8
17
18
y1 = -1.0
19
y2 = +10.0
20
21
xSteps = 25
22
ySteps = 60
23
24
dx = (x2 - x1) / xSteps # x axis step
25
dy = (y2 - y1) / ySteps # y axis step
26
27
rad = x1
28
while rad < x2:
29
y = math.exp(rad)
30
31
if y <= y1 or y >= y2:
32
print(" ")
33
else:
34
print_line(y1, y, dy, "+")
35
36
rad += dx
Output:
xxxxxxxxxx
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+