math.erfc() Method in Python:
The math.erfc() method returns a number’s complementary error function.
This method accepts values between – inf and + inf and returns between 0 and 2.
Syntax:
math.erfc(x)
Parameters
x: This is Required. It is a number used to calculate the complementary error function of
Return Value:
Returns a float value that represents a number’s complementary error function.
Examples:
Example1:
Input:
Given Number = 0.35
Output:
The given number's { 0.35 } complementary error function = 0.6206179464376897Example2:
Input:
Given Number = -5.6
Output:
The given number's { -5.6 } complementary error function = 1.9999999999999976math.erfc() Method with Examples in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Import math module using the import keyword.
- Give the number as static input and store it in a variable.
- Pass the given number as an argument to the math.erfc() function to get the given number’s complementary error function.
- Store it in another variable.
- Print the complementary error function of the given number.
- The Exit of the Program.
Below is the implementation:
# Import math module using the import keyword
import math
# Give the number as static input and store it in a variable.
gvn_numb = 0.35
# Pass the given number as an argument to the math.erfc() function to get
# the given number's complementary error function.
# Store it in another variable.
rslt = math.erfc(gvn_numb)
# Print the complementary error function of the given number.
print("The given number's {", gvn_numb,
"} complementary error function = ", rslt)
Output:
The given number's { 0.35 } complementary error function = 0.6206179464376897Similarly, try for other numbers.
import math
gvn_numb = -1
rslt = math.erfc(gvn_numb)
print("The given number's {", gvn_numb,
"} complementary error function = ", rslt)
Output:
The given number's { -1 } complementary error function = 1.842700792949715Method #2: Using Built-in Functions (User Input)
Approach:
- Import math module using the import keyword.
- Give the number as user input using the float(input()) function and store it in a variable.
- Pass the given number as an argument to the math.erfc() function to get the given number’s complementary error function.
- Store it in another variable.
- Print the complementary error function of the given number.
- The Exit of the Program.
Below is the implementation:
# Import math module using the import keyword
import math
# Give the number as user input using the float(input()) function and store it in a variable.
gvn_numb = float(input("Enter some random number = "))
# Pass the given number as an argument to the math.erfc() function to get
# the given number's complementary error function.
# Store it in another variable.
rslt = math.erfc(gvn_numb)
# Print the complementary error function of the given number.
print("The given number's {", gvn_numb,
"} complementary error function = ", rslt)
Output:
Enter some random number = -5.6
The given number's { -5.6 } complementary error function = 1.9999999999999976