Author name: Vikram Chiluka

Python Program for tan() Function

In the previous article, we have discussed Python Program for sin() Function
tan() Function in Python:

The tangent of a number is returned by the math.tan() method.

The tangent function’s mathematical formula is:

tan(A) = length of opposite side/length of adjacent side

Syntax:

math.tan(x)

Parameters:

x: This is Required. It is the number to calculate the tangent of. If the value is not a number, a TypeError is returned.

Return Value:

Returns a float value representing a number’s tangent.

  • The tan function returns the Tangent value if the number argument is positive or negative.
  • The tan function returns TypeError if the number argument is not a number.

Examples:

Example1:

Input:

Given first number (angle) = 60
Given second number (angle) = 45

Output:

The result after applying tan() function on above given first number 60  =  0.320040389379563
The result after applying tan() function on above given second number 45  =  1.6197751905438615

Example2:

Input:

Given first number (angle) = 90
Given second number (angle) = 15

Output:

The result after applying tan() function on above given first number 90  =  -1.995200412208242
The result after applying tan() function on above given second number 15  =  -0.8559934009085187

Program for tan() 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(angle) as static input and store it in another variable.
  • Apply math.tan() function to the given first number to get the tangent value of a given number (angle).
  • Store it in another variable.
  • Similarly, do the same for the other number.
  • Apply math.tan() 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 = [5, 15, 6, 7]
# Give the first number (angle) as static input and store it in another variable.
gvn_numb1 = 60
# Apply math.tan() function to the given first number to get the tangent value
# of a given number (angle).
# Store it in another variable.
fnl_rslt = math.tan(gvn_numb1)
print("The result after applying tan() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 45
print("The result after applying tan() function on above given second number",
      gvn_numb2, " = ", math.tan(gvn_numb2))
# Apply math.tan() function to the given list element and print it.
print(
    "The result after applying tan() function on given list element gvnlst[1] = ", math.tan(gvn_lst[1]))

Output:

The result after applying tan() function on above given first number 60  =  0.320040389379563
The result after applying tan() function on above given second number 45  =  1.6197751905438615
The result after applying tan() function on given list element gvnlst[1] =  -0.8559934009085187

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 (angle) as user input using the float(input()) function and store it in a variable.
  • Apply math.tan() function to the given first number to get the tangent value of a given number (angle).
  • Store it in another variable.
  • Similarly, do the same for the other number.
  • Apply math.tan() 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(angle) as user input using the float(input()) function
# and store it in a variable.
gvn_numb1 = float(input("Enter some random number = "))
# Apply math.tan() function to the given first number to get the tangent value
# of a given number (angle).
# Store it in another variable.
fnl_rslt = math.tan(gvn_numb1)
print("The result after applying tan() 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 tan() function on above given second number",
      gvn_numb2, " = ", math.tan(gvn_numb2))
# Apply math.tan() function to the given list element and print it.
print(
    "The result after applying tan() function on given list element gvnlst[2] = ", math.tan(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 10 20 30 40 50
Enter some random number = 90
The result after applying tan() function on above given first number 90.0 = -1.995200412208242
Enter some random number = 65
The result after applying tan() function on above given second number 65.0 = -1.4700382576631723
The result after applying tan() function on given list element gvnlst[2] = -6.405331196646276

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for tan() Function Read More »

Python Program for hypot() Function

In the previous article, we have discussed Python Program for atanh() Function
hypot() Function in Python:

The square root of the sum of squares of the specified arguments is returned by the Python hypot() function.

The Euclidean norm is returned by the math.hypot() method. The Euclidian norm is the distance between the origin and the given coordinates.

This method was only used prior to Python 3.8 to find the hypotenuse of a right-angled triangle: sqrt(x*x + y*y).

Since Python 3.8, this method is also used to compute the Euclidean norm. The coordinates passed are assumed to be like in n-dimensional cases (x1, x2, x3, …, xn). So sqrt(x1*x1 + x2*x2 + x3*x3…. xn*xn) is used to calculate Euclidean length from the origin.

Syntax:

math.hypot(x1, x2, x3,. . . .xn )

Parameters:

x1, x2, x3,. . . . ,xn: These are required. These are numbers. Two or more coordinates are represented by two or more points.

Return Value:

For n inputs, the return value is a float representing the Euclidean distance from the origin, or the hypotenuse of a right-angled triangle for two inputs.

  • If the value argument is both a positive and a negative integer, the hypot() function returns the Output.
  • If it’s not a number, the hypot() function throws a TypeError.

Examples:

Example1:

Input:

Given first number = 2
Given second number = 3

Output:

The result after applying hypot() function on above given first and second { 2 , 3 } numbers =  3.605551275463989

Example2:

Input:

Given first number = 4  
Given second number = 3

Output:

The result after applying hypot() function on above given first and second { 4 , 3 } numbers =  5.0

Program for hypot() 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.
  • Give the second number as static input and store it in another variable.
  • Apply math.hypot() function on the given first and the second numbers to get the square root of the sum of squares of the specified arguments.i.e (given first and second numbers )
  • Store it in another variable.
  • Print the above result which is the result after applying math.hypot() function.
  • Give the number as static input and store it in another variable.
  • Apply math.hypot() function to the given list element and above-given number 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 = [1, 2, 4, 0]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 2
# Give the second number as static input and store it in another variable.
gvn_numb2 = 3
# Apply math.hypot() function on the given first and the second numbers to get
# the square root of the sum of squares of the specified arguments.i.e
# (given first and second numbers )
# Store it in another variable.
fnl_rslt = math.hypot(gvn_numb1, gvn_numb2)
# Print the above result which is the result after applying math.hypot() function.
print("The result after applying hypot() function on above given first and second {",
      gvn_numb1, ",", gvn_numb2, "} numbers = ", fnl_rslt)
# Give the number as static input and store it in another variable.
gvn_numb3 = 5
# Apply math.hypot() function to the given list element and above given number
# and print it.
print("The result after applying hypot() function on the given list element gvn_lst[1] and above given number = ", math.hypot(
    gvn_lst[1], gvn_numb3))

Output:

The result after applying hypot() function on above given first and second { 2 , 3 } numbers =  3.605551275463989
The result after applying hypot() function on the given list element gvn_lst[1] and above given number =  5.385164807134504

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 first and second numbers respectively as user input using int(), map(), input(), and split() functions.
  • Store them in two separate variables.
  • Apply math.hypot() function on the given first and the second numbers to get the square root of the sum of squares of the specified arguments.i.e (given first and second numbers )
  • Store it in another variable.
  • Print the above result which is the result after applying math.hypot() function.
  • Give the number as user input using the int(input()) function and store it in another variable.
  • Apply math.hypot() function to the given list element and above-given number 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(int, input(
    'Enter some random List Elements separated by spaces = ').split()))
# Give first and second numbers respectively as user input using 
# int(), map(), input(), and split() functions.
gvn_numb1, gvn_numb2 = map(int, input(
    "Enter two random numbers separated by spaces = ").split())
# Apply math.hypot() function on the given first and the second numbers to get
# the square root of the sum of squares of the specified arguments.i.e
# (given first and second numbers )
# Store it in another variable.
fnl_rslt = math.hypot(gvn_numb1, gvn_numb2)
# Print the above result which is the result after applying math.hypot() function.
print("The result after applying hypot() function on above given first and second {",
      gvn_numb1, ",", gvn_numb2, "} numbers = ", fnl_rslt)
# Give the number as user input using the int(input()) function and store it in another variable.
gvn_numb3 = int(input("Enter some random number = "))
# Apply math.hypot() function to the given list element and above given number
# and print it.
print("The result after applying hypot() function on the given list element gvn_lst[2] and above given number = ", math.hypot(
    gvn_lst[2], gvn_numb3))

Output:

Enter some random List Elements separated by spaces = 2 3 4 1 
Enter two random numbers separated by spaces = 4 6
The result after applying hypot() function on above given first and second { 4 , 6 } numbers = 7.211102550927978
Enter some random number = 3
The result after applying hypot() function on the given list element gvn_lst[2] and above given number = 5.0

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for hypot() Function Read More »

Python Program for gamma() Function

In the previous article, we have discussed Python Program for tanh() Function
gamma() Function in Python:

The gamma function at a number is returned by the math.gamma() method.

Tip: Use the math.lgamma() method to find the log gamma value of a number.

Gamma Function’s Mathematical Formula:

Math.gamma(Number) = (Number – 1)!

Syntax:

math.gamma(x)

Parameters:

x: This is required. It is a number for which the gamma function must be found. If the number is a negative integer, a ValueError is returned. It throws a TypeError if it is not a number.

Return Value:

Returns a float value that represents the gamma function at x.

  • The gamma function returns the output if the number argument is a positive integer, positive or negative decimal.
  • The gamma function returns ValueError if the number argument is a negative integer.
  • If it’s not a number, the gamma function throws a TypeError.

Examples:

Example1:

Input:

Given first number = 6
Given second number = 2

Output:

The result after applying gamma() function on above given first number 6  =  120.0
The result after applying gamma() function on above given second number 2  =  1.0

Example2:

Input:

Given first number = -0.5
Given second number = 3

Output:

The result after applying gamma() function on above given first number -0.5  =  -3.544907701811032
The result after applying gamma() function on above given second number 3  =  2.0

Program for gamma() 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.gamma() function to the given first number to get the gamma value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.gamma() 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 = [2, -1.5, 3, 0.4]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 6
# Apply math.gamma() function to the given first number to get the gamma value
# of a given number.
# Store it in another variable.
fnl_rslt = math.gamma(gvn_numb1)
# Print the above result
print("The result after applying gamma() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 2
print("The result after applying gamma() function on above given second number",
      gvn_numb2, " = ", math.gamma(gvn_numb2))
# Apply math.gamma() function to the given list element and print it.
print(
    "The result after applying gamma() function on given list element gvnlst[1] = ", math.gamma(gvn_lst[1]))

Output:

The result after applying gamma() function on above given first number 6  =  120.0
The result after applying gamma() function on above given second number 2  =  1.0
The result after applying gamma() function on given list element gvnlst[1] =  2.3632718012073544

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.gamma() function to the given first number to get the gamma value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.gamma() 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.gamma() function to the given first number to get the gamma value
# of a given number.
# Store it in another variable.
fnl_rslt = math.gamma(gvn_numb1)
# Print the above result
print("The result after applying gamma() 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 gamma() function on above given second number",
      gvn_numb2, " = ", math.gamma(gvn_numb2))
# Apply math.gamma() function to the given list element and print it.
print(
    "The result after applying gamma() function on given list element gvnlst[2] = ", math.gamma(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 1 3 2 5 7
Enter some random number = 1.5
The result after applying gamma() function on above given first number 1.5 = 0.886226925452758
Enter some random number = 3
The result after applying gamma() function on above given second number 3.0 = 2.0
The result after applying gamma() function on given list element gvnlst[2] = 1.0

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for gamma() Function Read More »

Python Program for tanh() Function

In the previous article, we have discussed Python Program for sinh() Function
tanh() Function in Python:

The math.tanh() method returns a number’s hyperbolic tangent.

Syntax:

math.tanh(x)

Parameters:

x: This is Required. It is a number for which the hyperbolic tangent must be calculated. If the value is not a number, a TypeError is returned.

Return Value:

Returns a float value representing a number’s hyperbolic tangent.

  • The tanh() function returns the hyperbolic Tangent value if the number argument is positive or negative.
  • The tanh()  function returns TypeError if it is not a number.

Examples:

Example1:

Input:

Given first number = 7
Given second number = 5.5

Output:

The result after applying tanh() function on above given first number 7  =  0.9999983369439447
The result after applying tanh() function on above given second number 5.5  =  0.9999665971563038

Example2:

Input:

Given first number = 2
Given second number = 1

Output:

The result after applying tanh() function on above given first number 2  =  0.9640275800758169
The result after applying tanh() function on above given second number 1  =  0.7615941559557649

Program for cosh() 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.tanh() function to the given first number to get the hyperbolic tangent value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.tanh() 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 = [-1, 1, 3, 0.8]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 7
# Apply math.tanh() function to the given first number to get the hyperbolic
# tangent value of a given number.
# Store it in another variable.
fnl_rslt = math.tanh(gvn_numb1)
# Print the above result
print("The result after applying tanh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 5.5
print("The result after applying tanh() function on above given second number",
      gvn_numb2, " = ", math.tanh(gvn_numb2))
# Apply math.tanh() function to the given list element and print it.
print(
    "The result after applying tanh() function on given list element gvnlst[1] = ", math.tanh(gvn_lst[1]))

Output:

The result after applying tanh() function on above given first number 7  =  0.9999983369439447
The result after applying tanh() function on above given second number 5.5  =  0.9999665971563038
The result after applying tanh() function on given list element gvnlst[1] =  0.7615941559557649

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.tanh() function to the given first number to get the hyperbolic tangent value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.tanh() 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.tanh() function to the given first number to get the hyperbolic
# tangent value of a given number.
# Store it in another variable.
fnl_rslt = math.tanh(gvn_numb1)
# Print the above result
print("The result after applying tanh() 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 tanh() function on above given second number",
      gvn_numb2, " = ", math.tanh(gvn_numb2))
# Apply math.tanh() function to the given list element and print it.
print(
    "The result after applying tanh() function on given list element gvnlst[2] = ", math.tanh(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 2 3 10 4 1
Enter some random number = 2
The result after applying tanh() function on above given first number 2.0 = 0.9640275800758169
Enter some random number = 1
The result after applying tanh() function on above given second number 1.0 = 0.7615941559557649
The result after applying tanh() function on given list element gvnlst[2] = 0.9999999958776927

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for tanh() Function Read More »

Python Program for sinh() Function

In the previous article, we have discussed Python Program for cosh() Function
sinh() Function in Python:

The sinh() function in Python computes the Trigonometric Hyperbolic Sine for the given expression.

Syntax:

math.sinh(x)

Parameters:

x: This is Required. It is a number for which the hyperbolic sine must be calculated. If the value is not a number, a TypeError is returned.

Return Value:

Returns a float value representing a number’s hyperbolic sine.

  • The sinh() function returns the Sine value if the number argument is positive or negative.
  • The sinh function returns TypeError if the number argument is not a number.

Examples:

Example1:

Input:

Given first number = 0.3
Given second number = 1

Output:

The result after applying sinh() function on above given first number 0.3  =  0.3045202934471426
The result after applying sinh() function on above given second number 1  =  1.1752011936438014

Example2:

Input:

Given first number = 3
Given second number = 5.5

Output:

The result after applying sinh() function on above given first number 3  =  10.017874927409903
The result after applying sinh() function on above given second number 5.5  =  122.34392274639096

Program for cosh() 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.sinh() function to the given first number to get the hyperbolic sine value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.sinh() 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 = [-1, -3, 1, 0.8]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 0.3
# Apply math.sinh() function to the given first number to get the hyperbolic
# sine value of a given number.
# Store it in another variable.
fnl_rslt = math.sinh(gvn_numb1)
# Print the above result
print("The result after applying sinh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 1
print("The result after applying sinh() function on above given second number",
      gvn_numb2, " = ", math.sinh(gvn_numb2))
# Apply math.sinh() function to the given list element and print it.
print(
    "The result after applying sinh() function on given list element gvnlst[1] = ", math.sinh(gvn_lst[1]))

Output:

The result after applying sinh() function on above given first number 0.3  =  0.3045202934471426
The result after applying sinh() function on above given second number 1  =  1.1752011936438014
The result after applying sinh() function on given list element gvnlst[1] =  -10.017874927409903

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.sinh() function to the given first number to get the hyperbolic sine value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.sinh() 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.sinh() function to the given first number to get the hyperbolic
# sine value of a given number.
# Store it in another variable.
fnl_rslt = math.sinh(gvn_numb1)
# Print the above result
print("The result after applying sinh() 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 sinh() function on above given second number",
      gvn_numb2, " = ", math.sinh(gvn_numb2))
# Apply math.sinh() function to the given list element and print it.
print(
    "The result after applying sinh() function on given list element gvnlst[2] = ", math.sinh(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 1 1.5 2.5 3
Enter some random number = 3
The result after applying sinh() function on above given first number 3.0 = 10.017874927409903
Enter some random number = 5.5
The result after applying sinh() function on above given second number 5.5 = 122.34392274639096
The result after applying sinh() function on given list element gvnlst[2] = 6.0502044810397875

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for sinh() Function Read More »

Python Program for cosh() Function

In the previous article, we have discussed Python Program for isalpha() Function
cosh() Function in Python:

The math.cosh() method calculates a number’s hyperbolic cosine (equivalent to (exp(number) + exp(-number)) / 2).

Syntax:

math.cosh(x)

Parameters:

x: This is Required. It is a number for which the hyperbolic cosine must be calculated. If the value is not a number, a TypeError is returned.

Return Value:

Returns a float value representing a number’s hyperbolic cosine.

  • The cosh function returns the Hyperbolic Cosine value if the number argument is positive or negative.
  • The cosh function returns TypeError if the number argument is not a number.

Examples:

Example1:

Input:

Given first number = 0.4
Given second number = 1

Output:

The result after applying cosh() function on above given first number 0.4  =  1.081072371838455
The result after applying cosh() function on above given second number 1  =  1.5430806348152437

Example2:

Input:

Given first number = 6.5
Given second number = 2

Output:

The result after applying cosh() function on above given first number 6.5  =  332.5715682417774
The result after applying cosh() function on above given second number 2  =  3.7621956910836314

Program for cosh() 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.cosh() function to the given first number to get the hyperbolic cosine value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.cosh() 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 = [0.5, 0.2, 1, 0.8]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 0.4
# Apply math.cosh() function to the given first number to get the hyperbolic
# cosine value of a given number.
# Store it in another variable.
fnl_rslt = math.cosh(gvn_numb1)
# Print the above result
print("The result after applying cosh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 1
print("The result after applying cosh() function on above given second number",
      gvn_numb2, " = ", math.cosh(gvn_numb2))
# Apply math.cosh() function to the given list element and print it.
print(
    "The result after applying cosh() function on given list element gvnlst[1] = ", math.cosh(gvn_lst[1]))

Output:

The result after applying cosh() function on above given first number 0.4  =  1.081072371838455
The result after applying cosh() function on above given second number 1  =  1.5430806348152437
The result after applying cosh() function on given list element gvnlst[1] =  1.020066755619076

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.cosh() function to the given first number to get the hyperbolic cosine value of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.cosh() 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.cosh() function to the given first number to get the hyperbolic
# cosine value of a given number.
# Store it in another variable.
fnl_rslt = math.cosh(gvn_numb1)
# Print the above result.
print("The result after applying cosh() 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 cosh() function on above given second number",
      gvn_numb2, " = ", math.cosh(gvn_numb2))
# Apply math.cosh() function to the given list element and print it.
print(
    "The result after applying cosh() function on given list element gvnlst[2] = ", math.cosh(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 2 3 4 1 5
Enter some random number = 6.5
The result after applying cosh() function on above given first number 6.5 = 332.5715682417774
Enter some random number = 2
The result after applying cosh() function on above given second number 2.0 = 3.7621956910836314
The result after applying cosh() function on given list element gvnlst[2] = 27.308232836016487

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for cosh() Function Read More »

Python Program for acos() Function

In the previous article, we have discussed Python Program for log() Function
acos() Function in Python:

The math.acos() method returns a number’s arc cosine value. Python acos, also known as Arc cosine, is the inverse of a cosine.

Note: It should be noted that the parameter passed to math.acos() must be between -1 and 1.

Tip: The value of PI will be returned by math.acos(-1).

Syntax:

math.acos(x)

Parameters:

x: This is required. It is a number between -1 and 1. If x is not a number, a TypeError is returned.

Return Value:

Returns a float value which represents a number’s arc cosine.

  • The acos() function returns the Arc Cosine value if the number argument is positive or negative.
  • The acos() function returns TypeError if it is not a number.
  • If it is not between -1 and 1, the acos() function returns ValueError.

Examples:

Example1:

Input:

Given first number = 0.5
Given second number = 1

Output:

The result after applying acos() function on above given first number 0.5  =  1.0471975511965979
The result after applying acos() function on above given second number 1  =  0.0

Example2:

Input:

Given first number = 0.3
Given second number = -0.2

Output:

The result after applying acos() function on above given first number 0.3  =  1.2661036727794992
The result after applying acos() function on above given second number -0.2  =  1.7721542475852274

Program for acos() 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.acos() function to the given first number to get the arc cosine value (inverse of cosine) of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.acos() 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 = [0.5, 0.2, 1, 0.8]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 0.5
# Apply math.acos() function to the given first number to get arc cosine value
# (inverse of cosine) of a given number.
# Store it in another variable.
fnl_rslt = math.acos(gvn_numb1)
print("The result after applying acos() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 1
print("The result after applying acos() function on above given second number",
      gvn_numb2, " = ", math.acos(gvn_numb2))
# Apply math.acos() function to the given list element and print it.
print(
    "The result after applying acos() function on given list element gvnlst[1] = ", math.acos(gvn_lst[1]))

Output:

The result after applying acos() function on above given first number 0.5  =  1.0471975511965979
The result after applying acos() function on above given second number 1  =  0.0
The result after applying acos() function on given list element gvnlst[1] =  1.369438406004566

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.acos() function to the given first number to get the arc cosine value (inverse of cosine) of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.acos() 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.acos() function to the given first number to get arc cosine value
# (inverse of cosine) of a given number.
# Store it in another variable.
fnl_rslt = math.acos(gvn_numb1)
print("The result after applying acos() 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 acos() function on above given second number",
      gvn_numb2, " = ", math.acos(gvn_numb2))
# Apply math.acos() function to the given list element and print it.
print(
    "The result after applying acos() function on given list element gvnlst[2] = ", math.acos(gvn_lst[2]))


Output:

Enter some random List Elements separated by spaces = 1 2 0.3 0.5
Enter some random number = 0.38
The result after applying acos() function on above given first number 0.38 = 1.181000030320636
Enter some random number = 0.6
The result after applying acos() function on above given second number 0.6 = 0.9272952180016123
The result after applying acos() function on given list element gvnlst[2] = 1.2661036727794992

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for acos() Function Read More »

Python Program for expm1() Function

In the previous article, we have discussed Python Program for exp() Function
expm1() Function in Python:

Ex – 1 is returned by the math.expm1() method.

‘E’ is the natural logarithmic system’s base (approximately 2.718282), and x is the number passed to it.

This function is more precise than using math. exp() and subtracting 1.

Syntax:

math.expm1(x)

Parameters:

x: This is required. It is a number. The exponent is specified.

Return Value:

It returns a value float value which represents  Ex – 1.

Examples:

Example1:

Input:

Given Number = 3

Output:

The result after applying expm1() function on above given number 3  =  19.085536923187668

Example2:

Input:

Given Number = 5.5

Output:

The result after applying expm1() function on above given number 5.5  =  243.69193226422038

Program for expm1() 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.expm1() function to the given first number to calculate the value E raised to the power of given number-1.(E =approximately 2.718282)
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.expm1() 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 = [9, 4, 5, 2, 1]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 3
# Apply math.expm1() function to the given first number to calculate the value
# E raised to the power of given number-1.(E =approximately 2.718282)
# Store it in another variable.
fnl_rslt = math.expm1(gvn_numb1)
print("The result after applying expm1() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 5.5
print("The result after applying expm1() function on above given second number",
      gvn_numb2, " = ", math.expm1(gvn_numb2))
# Apply math.expm1() function to the given list element and print it.
print(
    "The result after applying expm1() function on given list element gvnlst[1] = ", math.expm1(gvn_lst[1]))

Output:

The result after applying expm1() function on above given first number 3  =  19.085536923187668
The result after applying expm1() function on above given second number 5.5  =  243.69193226422038
The result after applying expm1() function on given list element gvnlst[1] =  53.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.expm1() function to the given first number to calculate the value E raised to the power of given number-1.(E =approximately 2.718282)
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.expm1() 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.expm1() function to the given first number to calculate the value
# E raised to the power of given number-1.(E =approximately 2.718282)
# Store it in another variable.
fnl_rslt = math.expm1(gvn_numb1)
print("The result after applying expm1() 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 expm1() function on above given second number",
      gvn_numb2, " = ", math.expm1(gvn_numb2))
# Apply math.expm1() function to the given list element and print it.
print(
    "The result after applying expm1() function on given list element gvnlst[2] = ", math.expm1(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 46 2 1 80 2
Enter some random number = 4
The result after applying expm1() function on above given first number 4.0 = 53.598150033144236
Enter some random number = 3.5
The result after applying expm1() function on above given second number 3.5 = 32.11545195869231
The result after applying expm1() function on given list element gvnlst[2] = 1.718281828459045

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for expm1() Function Read More »

Python Program for exp() Function

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.

Python Program for exp() Function Read More »

Python Program for log() Function

In the previous article, we have discussed Python Program for expm1() Function
log() Function in Python:

The math.log() method returns the natural logarithm of a number or the base logarithm of a number.

Syntax:

math.log(x, base)

Parameters:

x: This is required. It is a number. It Specifies the value for which the logarithm should be calculated. If the value is 0 or a negative number, a ValueError is returned. If the value is not a number, a TypeError is returned.

base: This is optional. The logarithmic base that should be used. ‘e’ is the default.

Return Value:

Returns a float value corresponding to the natural logarithm of a number or the logarithm of a number to base.

  • The log function returns the output if the number argument is positive.
  • If the number is negative or zero, the log function throws a ValueError.
  • If it is not a number, the log function throws a TypeError.

Examples:

Example1:

Input:

Given first number = 1
Given second number = 6

Output:

The result after applying log() function on above given first number 1  =  0.0
The result after applying log() function on above given second number 6  =  1.791759469228055

Example2:

Input:

Given first number = 7
Given second number = 9

Output:

The result after applying log() function on above given first number 7  =  1.9459101490553132
The result after applying log() function on above given second number 9  =  2.1972245773362196

Program for log() 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.log() function to the given first number to get the natural logarithm or the base logarithm of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply the math.log() 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 = [10, 5, 20, 25, 12]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 1
# Apply math.log() function to the given first number to get the natural logarithm
# or the base logarithm of a given number.
# Store it in another variable.
fnl_rslt = math.log(gvn_numb1)
print("The result after applying log() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 6
print("The result after applying log() function on above given second number",
      gvn_numb2, " = ", math.log(gvn_numb2))
# Apply math.log() function to the given list element and print it.
print(
    "The result after applying log() function on given list element gvnlst[1] = ", math.log(gvn_lst[1]))

Output:

The result after applying log() function on above given first number 1  =  0.0
The result after applying log() function on above given second number 6  =  1.791759469228055
The result after applying log() function on given list element gvnlst[1] =  1.6094379124341003

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.log() function to the given first number to get the natural logarithm or the base logarithm of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply the math.log() 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.log() function to the given first number to get the natural logarithm
# or the base logarithm of a given number.
# Store it in another variable.
fnl_rslt = math.log(gvn_numb1)
print("The result after applying log() 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 log() function on above given second number",
      gvn_numb2, " = ", math.log(gvn_numb2))
# Apply math.log() function to the given list element and print it.
print(
    "The result after applying log() function on given list element gvnlst[2] = ", math.log(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 4 5 3 1 2
Enter some random number = 7
The result after applying log() function on above given first number 7.0 = 1.9459101490553132
Enter some random number = 9
The result after applying log() function on above given second number 9.0 = 2.1972245773362196
The result after applying log() function on given list element gvnlst[2] = 1.0986122886681098

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for log() Function Read More »