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
.
import math
print(math.exp(-100)) # 3.720075976020836E-44
print(math.exp(-1)) # 0.36787944117144233
print(math.exp(0)) # 1
print(math.exp(1)) # 2.718281828459045
print(math.exp(100)) # 2.6881171418161356E43
print(math.exp(-math.inf)) # 0
print(math.exp(math.inf)) # ∞ / +Infinity
print(math.exp(math.nan)) # NaN
1. Documentation
Syntax |
|
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 |
|
2. Reversed console plot example
import math
def print_line(y1, y2, dy, character):
line = ""
y = y1
while y < y2:
line += " "
y += dy
print(line, character)
x1 = -4
x2 = 2.8
y1 = -1.0
y2 = +10.0
xSteps = 25
ySteps = 60
dx = (x2 - x1) / xSteps # x axis step
dy = (y2 - y1) / ySteps # y axis step
rad = x1
while rad < x2:
y = math.exp(rad)
if y <= y1 or y >= y2:
print(" ")
else:
print_line(y1, y, dy, "+")
rad += dx
Output:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+