Python

Program for Python String isalpha() Method

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

If all of the characters are alphabet letters, the isalpha() method returns True (a-z).

(space)!#%&? etc are examples of characters that are not alphabets.

Syntax:

string.isalpha()

Parameters: This function has no parameters.

Examples:

Example1:

Input:

Given first string = "pythonprograms"
Given second string = "123456good morning"

Output:

The above given first string is : pythonprograms
The given first string after applying isalpha() function: True
The above given second string is : 123456good morning
The given second string after applying isalpha() function: False

Example2:

Input:

Given first string = "hello123this is python programming platform"
Given second string = "hellogoodmorning"

Output:

The above given first string is : hello123this is python programming platform
The given first string after applying isalpha() function: False
The above given second string is : hellogoodmorning
The given second string after applying isalpha() function: True

Program for isalpha() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply isalpha() function to the given first string that returns true if all of the characters are alphabet letters.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "hello123this is python programming platform"
# Apply isalpha() function to the given first string that returns true if
# all of the characters are alphabet letters.
# Store it in another variable.
rslt_str1 = gvn_fststr.isalpha()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalpha() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "hellogoodmorning"
rslt_str2 = gvn_scndstr.isalpha()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalpha() function:", rslt_str2)

Output:

The above given first string is : hello123this is python programming platform
The given first string after applying isalpha() function: False
The above given second string is : hellogoodmorning
The given second string after applying isalpha() function: True

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply isalpha() function to the given first string that returns true if all of the characters are alphabet letters.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply isalpha() function to the given first string that returns true if
# all of the characters are alphabet letters.
# Store it in another variable.
rslt_str1 = gvn_fststr.isalpha()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalpha() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.isalpha()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalpha() function:", rslt_str2)

Output:

Enter some Random String = pythonprograms
The above given first string is : pythonprograms
The given first string after applying isalpha() function: True
Enter some Random String = 123456good morning
The above given second string is : 123456good morning
The given second string after applying isalpha() function: False

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String isalpha() Method Read More »

Program for Python String isalnum() Method

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

The isalnum() method returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9).

(space)!#%&? etc are examples of characters that are not alphanumeric.

Syntax:

string.isalnum()

Parameters: This function has no parameters.

Examples:

Example1:

Input:

Given first string = "pythonprograms"
Given second string = "10345 @@@good morning"

Output:

The above given first string is : pythonprograms
The given first string after applying isalnum() function: True
The above given second string is : 10345 @@@good morning
The given second string after applying isalnum() function: False

Example2:

Input:

Given first string = "hello this is python programming platform"
Given second string = "hello123"

Output:

The above given first string is : hello this is python programming platform
The given first string after applying isalnum() function: False
The above given second string is : hello123
The given second string after applying isalnum() function: True

Program for isalnum() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply isalnum() function to the given first string that returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9).
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "pythonprograms"
# Apply isalnum() function to the given first string that returns a value
# True if all of the characters are alphanumeric, which means they are alphabet
# letters (a-z) and numbers (0-9).
# Store it in another variable.
rslt_str1 = gvn_fststr.isalnum()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalnum() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "10345 @@@good morning"
rslt_str2 = gvn_scndstr.isalnum()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalnum() function:", rslt_str2)

Output:

The above given first string is : pythonprograms
The given first string after applying isalnum() function: True
The above given second string is : 10345 @@@good morning
The given second string after applying isalnum() function: False

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply isalnum() function to the given first string that returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9).
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply isalnum() function to the given first string that returns a value
# True if all of the characters are alphanumeric, which means they are alphabet
# letters (a-z) and numbers (0-9).
# Store it in another variable.
rslt_str1 = gvn_fststr.isalnum()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalnum() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.isalnum()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalnum() function:", rslt_str2)

Output:

Enter some Random String = hello this is python programming platform
The above given first string is : hello this is python programming platform
The given first string after applying isalnum() function: False
Enter some Random String = hello123
The above given second string is : hello123
The given second string after applying isalnum() function: True

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String isalnum() Method Read More »

Program for Python String center() Method

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

The center () method will center align the string, using a specified character as the fill character (space is the default).

Syntax:

String.center(Length, character)

Parameters:

length: This is required. It is the length of the string returned.

character: This is optional. Fills the blanks on each side with a character. The default value is ” ” (space).

Note: This parameter is optional, and if omitted, the white spaces are used as the default parameter by the centre Function. Please specify the Characters you want to use in the remaining width if you want to change the default value.

Examples:

Example1:

Input:

Given first string = "python"
Given length = 30 
Given character = '-'

Output:

The above given first string is : python
The given first string after applying center() function: ------------python------------

Example2:

Input:

Given second string = "GOODMORNING"
Given length = 17
Given character = '#'

Output:

The above given second string is : GOODMORNING
The given second string after applying center() function: ###GOODMORNING###

Program for center() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Give the length as static input and store it in another variable.
  • Give the character as static input and store it in another variable.
  • Apply center () method to the given string for the given length and character which will center align the string.
  • Store it in another variable.
  • Print the above-given string.
  • Print the above-given string after applying the center() function.
  • Similarly, do the same for the other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "python"
# Give the length as static input and store it in another variable.
gvn_lengt = 30
# Give the character as static input and store it in another variable.
gvn_chactr = '-'
# Apply center () method to the given string for the given length and character
# which will center align the string.
# Store it in another variable.
rslt_str1 = gvn_fststr.center(gvn_lengt, gvn_chactr)
# Print the above given string
print("The above given first string is :", gvn_fststr)
# Print the above given string after applying center() function.
print("The given first string after applying center() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "GOODMORNING"
gvn_lengt2 = 17
gvn_chactr2 = '#'
rslt_str2 = gvn_scndstr.center(gvn_lengt2, gvn_chactr2)
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying center() function:", rslt_str2)

Output:

The above given first string is : python
The given first string after applying center() function: ------------python------------
The above given second string is : GOODMORNING
The given second string after applying center() function: ###GOODMORNING###

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Give the length as user input using the int(input()) function and store it in another variable.
  • Give the character as user input using the input() function and store it in another variable.
  • Apply center () method to the given string for the given length and character which will center align the string.
  • Store it in another variable.
  • Print the above-given string.
  • Print the above-given string after applying the center() function.
  • Similarly, do the same for the other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr =  input("Enter some random string = ")
# Give the length as user input using the int(input()) function and store it in another variable.
gvn_lengt = int(input("Enter some random number = "))
# Give the character as user input using the input() function and store it in another variable.
gvn_chactr = input("Enter some random charcter = ")
# Apply center () method to the given string for the given length and character
# which will center align the string.
# Store it in another variable.
rslt_str1 = gvn_fststr.center(gvn_lengt, gvn_chactr)
# Print the above given string
print("The above given first string is :", gvn_fststr)
# Print the above given string after applying center() function.
print("The given first string after applying center() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some random string = ")
gvn_lengt2 =  int(input("Enter some random number = "))
gvn_chactr2 = input("Enter some random charcter = ")
rslt_str2 = gvn_scndstr.center(gvn_lengt2, gvn_chactr2)
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying center() function:", rslt_str2)

Output:

Enter some random string = welcome
Enter some random number = 16
Enter some random charcter = !
The above given first string is : welcome
The given first string after applying center() function: !!!!welcome!!!!!
Enter some random string = PYTHONPLATFORM
Enter some random number = 8
Enter some random charcter = *
The above given second string is : PYTHONPLATFORM
The given second string after applying center() function: PYTHONPLATFORM

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

 

Program for Python String center() Method Read More »

Program for Python String casefold() Method

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

The casefold() method produces a string in which all of the characters are lower case.

This method is similar to lower(), but the casefold() method is stronger and more aggressive, which means it will convert more characters into lower case and find more matches when comparing two strings that have both been converted using the casefold() method.

Syntax:

string.casefold()

Parameters: This function doesn’t have any parameters.

Examples:

Example1:

Input:

Given first string = "hello this is BTECHGEEKS"
Given second string = "10345 GOOD MORNING btechgeeks"

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying casefold() function: hello this is btechgeeks
The above given second string is : 10345 GOOD MORNING btechgeeks
The given second string after applying casefold() function: 10345 good morning btechgeeks

Example2:

Input:

Given first string = "HeLLO ThiS is BTECHgeeks 12345"
Given second string = "GOOD MORNING THIS IS BTECHGEEKS"

Output:

The above given first string is : HeLLO ThiS is BTECHgeeks 12345
The given first string after applying casefold() function: hello this is btechgeeks 12345
The above given second string is : GOOD MORNING THIS IS BTECHGEEKS
The given second string after applying casefold() function: good morning this is btechgeeks

Program for casefold() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply casefold() function to the given first string to get the string in which all of the characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying casefold() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "hello this is BTECHGEEKS"
# Apply casefold() function to the given first string to get the string
# in which all of the characters are lower case.
# Store it in another variable.
rslt_str1 = gvn_fststr.casefold()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying casefold() function.
print("The given first string after applying casefold() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "10345 GOOD MORNING btechgeeks"
rslt_str2 = gvn_scndstr.casefold()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying casefold() function:", rslt_str2)

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying casefold() function: hello this is btechgeeks
The above given second string is : 10345 GOOD MORNING btechgeeks
The given second string after applying casefold() function: 10345 good morning btechgeeks

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply casefold() function to the given first string to get the string in which all of the characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying casefold() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply casefold() function to the given first string to get the string
# in which all of the characters are lower case.
# Store it in another variable.
rslt_str1 = gvn_fststr.casefold()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying casefold() function.
print("The given first string after applying casefold() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.casefold()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying casefold() function:", rslt_str2)

Output:

Enter some Random String = hello all this IS BTECHGEEKS
The above given first string is : hello all this IS BTECHGEEKS
The given first string after applying casefold() function: hello all this is btechgeeks
Enter some Random String = GOOD MORNING THIS IS BTECHGEEKS
The above given second string is : GOOD MORNING THIS IS BTECHGEEKS
The given second string after applying casefold() function: good morning this is btechgeeks

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String casefold() Method Read More »

Program for Python String capitalize() Function

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

The capitalize() method returns a string in which the first character is upper case and the remaining characters are lower case.

Non-letters are not capitalized by the string capitalize function.

Syntax:

string.capitalize()

Parameters: This function doesn’t have any parameters.

Examples:

Example1:

Input:

Given first string = "hello this is BTECHGEEKS"
Given second string = "10345 good morning btechgeeks"

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying capitalize() function: Hello this is btechgeeks
The above given second string is : 10345 good morning btechgeeks
The given second string after applying capitalize() function: 10345 good morning btechgeeks

Example2:

Input:

Given first string = "heLLO 1256 GOOd MOrning"
Given second string = "Hello btech137GEEKS"

Output:

The above given first string is : heLLO 1256 GOOd MOrning
The given first string after applying capitalize() function: Hello 1256 good morning
The above given second string is : Hello btech137GEEKS
The given second string after applying capitalize() function: Hello btech137geeks

Program for capitalize() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply capitalize() function to the given first string to get the string in which the first character is upper case and the remaining characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying capitalize() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "hello this is BTECHGEEKS"
# Apply capitalize() function to the given first string to get the string in which
# the first character is upper case and the remaining characters are lower case.
# Store it in another variable.
capitize_str1 = gvn_fststr.capitalize()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying capitalize() function.
print("The given first string after applying capitalize() function:", capitize_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "10345 good morning btechgeeks"
capitize_str2 = gvn_scndstr.capitalize()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying capitalize() function:", capitize_str2)

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying capitalize() function: Hello this is btechgeeks
The above given second string is : 10345 good morning btechgeeks
The given second string after applying capitalize() function: 10345 good morning btechgeeks

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply capitalize() function to the given first string to get the string in which the first character is upper case and the remaining characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying capitalize() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply capitalize() function to the given first string to get the string in which
# the first character is upper case and the remaining characters are lower case.
# Store it in another variable.
capitize_str1 = gvn_fststr.capitalize()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying capitalize() function.
print("The given first string after applying capitalize() function:", capitize_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
capitize_str2 = gvn_scndstr.capitalize()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying capitalize() function:", capitize_str2)

Output:

Enter some Random String = heLLO 1256 GOOd MOrning
The above given first string is : heLLO 1256 GOOd MOrning
The given first string after applying capitalize() function: Hello 1256 good morning
Enter some Random String = Hello btech137GEEKS
The above given second string is : Hello btech137GEEKS
The given second string after applying capitalize() function: Hello btech137geeks

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String capitalize() Function Read More »

Python Program for asinh() Function

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

The inverse hyperbolic sine of a number is returned by the math.asinh() method.

Syntax:

math.asinh(x)

Parameter:

x: This is required. It is a positive or a negative number. If x is not a number, a TypeError is returned.

Return Value:

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

  • The asinh function returns the hyperbolic Arc Sine value if the number argument is positive or negative.
  • The asinh functions return TypeError if it is not a number.

Examples:

Example1:

Input:

Given first number = 9
Given second number = 45

Output:

The result after applying asinh() function on above given first number 9  =  2.8934439858858716
The result after applying asinh() function on above given second number 45  =  4.49993310426429

Example2:

Input:

Given first number = 30
Given second number = 60

Output:

The result after applying asinh() function on above given first number 30  =  4.09462222433053
The result after applying asinh() function on above given second number 60  =  4.78756117999381

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

Output:

The result after applying asinh() function on above given first number 9  =  2.8934439858858716
The result after applying asinh() function on above given second number 45  =  4.49993310426429
The result after applying asinh() function on given list element gvnlst[1] =  2.0947125472611012

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

Output:

Enter some random List Elements separated by spaces = 15 25 35 45
Enter some random number = 30
The result after applying asinh() function on above given first number 30.0 = 4.09462222433053
Enter some random number = 60
The result after applying asinh() function on above given second number 60.0 = 4.78756117999381
The result after applying asinh() function on given list element gvnlst[2] = 4.248699261236361

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

Python Program for asinh() Function Read More »

Python Program for atanh() Function

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

The inverse hyperbolic tangent of a number is returned by the math.atanh() method.

Note: It should be noted that the parameter passed in math.atanh() must be between -0.99 and 0.99.

Syntax:

math.atanh(x)

Parameters:

x: This is required. It is a number between -0.99 and 0.99 that is positive or negative. If x is not a number, a TypeError is returned.

Return Value:

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

  • The atanh function returns the Hyperbolic Arc Tangent value if the number argument is both positive and negative.
  • The atanh function returns ValueError if it is not between -1 (exclude) and 1 (exclude).
  • If it is not a number, the atanh function throws a TypeError.

Examples:

Example1:

Input:

Given first number = 0.6
Given second number = -0.8

Output:

The result after applying atanh() function on above given first number 0.6  =  0.6931471805599453
The result after applying atanh() function on above given second number -0.8  =  -1.0986122886681098

Example2:

Input:

Given first number = 0.54
Given second number = -0.9

Output:

The result after applying atanh() function on above given first number 0.54  =  0.6041556029622671
The result after applying atanh() function on above given second number -0.9  =  -1.4722194895832204

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

Output:

The result after applying atanh() function on above given first number 0.6  =  0.6931471805599453
The result after applying atanh() function on above given second number -0.8  =  -1.0986122886681098
The result after applying atanh() function on given list element gvnlst[1] =  0.36544375427139614

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

Output:

Enter some random List Elements separated by spaces = 0.1 0.2 -0.3 4.4
Enter some random number = 0.54
The result after applying atanh() function on above given first number 0.54 = 0.6041556029622671
Enter some random number = -0.9
The result after applying atanh() function on above given second number -0.9 = -1.4722194895832204
The result after applying atanh() function on given list element gvnlst[2] = -0.30951960420311175

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

Python Program for atanh() Function Read More »

Python Program for acosh() Function

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

The inverse hyperbolic cosine of a number is returned by the math.acosh() method.

It should be noted that the parameter passed to acosh() must be greater than or equal to 1.

Syntax:

math.acosh(x)

Parameter:

x: This is required. A positive number greater than or equal to one. If x is not a number, a TypeError is returned.

Return Value:

The inverse hyperbolic cosine of x is represented as a float in the return value.

  • The acosh function returns the hyperbolic Arc Cosine value if the number argument is positive.
  • If the value is negative, the acosh function returns ValueError.
  • If it’s not a number, the acosh function throws a TypeError.

Examples:

Example1:

Input:

Given first number = 8
Given second number = 36

Output:

The result after applying acosh() function on above given first number 8  =  2.7686593833135738
The result after applying acosh() function on above given second number 36  =  4.276473161941219

Example2:

Input:

Given first number = 14.5
Given second number = 25

Output:

The result after applying acosh() function on above given first number 14.5  =  3.366104642925109
The result after applying acosh() function on above given second number 25  =  3.9116227652145885

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

Output:

The result after applying acosh() function on above given first number 8  =  2.7686593833135738
The result after applying acosh() function on above given second number 36  =  4.276473161941219
The result after applying acosh() function on given list element gvnlst[1] =  2.2924316695611777

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

Output:

Enter some random List Elements separated by spaces = 10 20 30 50 
Enter some random number = 14.5
The result after applying acosh() function on above given first number 14.5 = 3.366104642925109
Enter some random number = 25
The result after applying acosh() function on above given second number 25.0 = 3.9116227652145885
The result after applying acosh() function on given list element gvnlst[2] = 4.0940666686320855

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

Python Program for acosh() Function Read More »

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 »