In the previous article, we have discussed Python Program for modf() Function
exp() Function in Python:
The method math.exp() returns E raised to the power of x (Ex).
‘E’ is the natural logarithmic system’s base (approximately 2.718282), and x is the number passed to it.
Syntax:
math.exp(x)
Parameters:
x: This is required. The exponent is specified by this.
Return Value:
A float value representing ‘E’ raised to the power of x is returned as the return value.
Examples:
Example1:
Input:
Given Number = 5
Output:
The result after applying exp() function on above given number 5 = 148.4131591025766
Example2:
Input:
Given Number = 7.5
Output:
The result after applying exp() function on above given number 7.5 = 1808.0424144560632
Program for exp() Function in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Import math module using the import keyword.
- Give the list as static input and store it in a variable.
- Give the first number as static input and store it in another variable.
- Apply math.exp() function to the given first number to calculate the value E raised to the power of given number.(E =approximately 2.718282)
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.exp() function to the given list element and print it.
- The Exit of Program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the list as static input and store it in a variable. gvn_lst = [7, 4, 6, 14, 10] # Give the first number as static input and store it in another variable. gvn_numb1 = 5 # Apply math.exp() function to the given first number to calculate the value # E raised to the power of given number.(E =approximately 2.718282) # Store it in another variable. fnl_rslt = math.exp(gvn_numb1) print("The result after applying exp() function on above given first number", gvn_numb1, " = ", fnl_rslt) # similarly do the same for the other number. gvn_numb2 = 7.5 print("The result after applying exp() function on above given second number", gvn_numb2, " = ", math.exp(gvn_numb2)) # Apply math.exp() function to the given list element and print it. print( "The result after applying exp() function on given list element gvnlst[1] = ", math.exp(gvn_lst[1]))
Output:
The result after applying exp() function on above given first number 5 = 148.4131591025766 The result after applying exp() function on above given second number 7.5 = 1808.0424144560632 The result after applying exp() function on given list element gvnlst[1] = 54.598150033144236
Method #2: Using Built-in Functions (User Input)
Approach:
- Import math module using the import keyword.
- Give the list as user input using list(),map(),input(),and split() functions.
- Store it in a variable.
- Give the first number as user input using the float(input()) function and store it in a variable.
- Apply math.exp() function to the given first number to calculate the value E raised to the power of the given number.(E =approximately 2.718282)
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.exp() function to the given list element and print it.
- The Exit of Program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the list as user input using list(),map(),input(),and split() functions. # Store it in a variable. gvn_lst = list(map(float, input( 'Enter some random List Elements separated by spaces = ').split())) # Give the first number as user input using the float(input()) function # and store it in a variable. gvn_numb1 = float(input("Enter some random number = ")) # Apply math.exp() function to the given first number to calculate the value # E raised to the power of given number.(E =approximately 2.718282) # Store it in another variable. fnl_rslt = math.exp(gvn_numb1) print("The result after applying exp() function on above given first number", gvn_numb1, " = ", fnl_rslt) # similarly do the same for the other number. gvn_numb2 = float(input("Enter some random number = ")) print("The result after applying exp() function on above given second number", gvn_numb2, " = ", math.exp(gvn_numb2)) # Apply math.exp() function to the given list element and print it. print( "The result after applying exp() function on given list element gvnlst[3] = ", math.exp(gvn_lst[3]))
Output:
Enter some random List Elements separated by spaces = 1 3 5 6 8 Enter some random number = 3.5 The result after applying exp() function on above given first number 3.5 = 33.11545195869231 Enter some random number = 9 The result after applying exp() function on above given second number 9.0 = 8103.083927575384 The result after applying exp() function on given list element gvnlst[3] = 403.4287934927351
Read all the mathematical functions available in Python and understand how to implement them in your program by using the tutorial of Python Mathematical Methods Examples.