Author name: Vikram Chiluka

Python Program for floor() Function

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

If necessary, the math.floor() method rounds a number DOWN to the nearest integer and returns the result.

The python math. floor() function returns the nearest integer value that is less than or equal to the specified expression or Value.

Syntax:

math.floor(number)

Parameter Values:

number: This is required. It Sets the number to round down.

Return Value: The return value is an int value that represents the rounded number.

Examples:

Example1:

Input:

Given tuple = (1.3, 10.04, -4.4, 7.7, 9.45)
Given List = [2.8, 3.4, -1.7, -6.82, 12.2]

Output:

Given positive number 9.2 floor value = 9.00
Given negative number -8.6 floor value = -9.00
Given Tuple element(gvn_tupl[3]) floor value = 7.00
Given Tuple element(gvn_lst[2]) floor value = -2.00
The floor of pi is:  3
Given multiple number(35+40-10.3) floor value  = 64.00

Example2:

Input:

Given tuple = (2.4, 85.67, 37.8, -25.5)
Given List =  [45.9, 11.32, -25, 6, 12.8, -10]

Output:

Given positive number 30.1 floor value = 30.00
Given negative number -20.4 floor value = -21.00
Given Tuple element(gvn_tupl[0]) floor value = 2.00
Given Tuple element(gvn_lst[3]) floor value = 6.00
The floor of pi is:  3
Given multiple number(23-10+5) floor value  = 18.00

Program for floor() Function in Python

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

Approach:

  • Import math module using the import keyword.
  • Give the tuple as static input and store it in a variable.
  • Give the list as static input and store it in another variable.
  • Apply math. floor() function to any positive number and print it.
  • Apply math. floor() function to any negative number and print it.
  • Apply math. floor() function to the given tuple element and print it.
  • Apply math. floor() function to the pi value and print it.
  • Apply math. floor() function to any multiple numbers and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the tuple as static input and store it in a variable.
gvn_tupl = (1.3, 10.04, -4.4, 7.7, 9.45)
# Give the list as static input and store it in another variable.
gvn_lst = [2.8, 3.4, -1.7, -6.82, 12.2]
# Apply math. floor() function to any positive number and print it.
print('Given positive number 9.2 floor value = %.2f' % math.floor(9.2))
# Apply math. floor() function to any negative number and print it.
print('Given negative number -8.6 floor value = %.2f' % math.floor(-8.6))
# Apply math. floor() function to the given tuple element and print it.
print('Given Tuple element(gvn_tupl[3]) floor value = %.2f' % math.floor(
    gvn_tupl[3]))
# Apply math. floor() function to the given list element and print it.
print(
    'Given Tuple element(gvn_lst[2]) floor value = %.2f' % math.floor(gvn_lst[2]))
# Apply math. floor() function to the pi value and print it.
print("The floor of pi is: ", math.floor(math.pi))
# Apply math. floor() function to any multiple numbers and print it.
print('Given multiple number(35+40-10.3) floor value  = %.2f' %
      math.floor(35+40-10.3))

Output:

Given positive number 9.2 floor value = 9.00
Given negative number -8.6 floor value = -9.00
Given Tuple element(gvn_tupl[3]) floor value = 7.00
Given Tuple element(gvn_lst[2]) floor value = -2.00
The floor of pi is:  3
Given multiple number(35+40-10.3) floor value  = 64.00

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

Approach:

  • Import math module using the import keyword.
  • Give the tuple as user input using list(),map(),input(),and split() functions.
  • Store it in a variable.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in another variable.
  • Give the positive number as user input using the float(input()) function
  • Store it in another variable.
  • Apply math. floor() function to the given positive number and print it.
  • Give the negative number as user input using the float(input()) function and store it in another variable.
  • Apply math. floor() function to the given negative number and print it.
  • Apply math. floor() function to the given tuple element and print it.
  • Apply math. floor() 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 tuple as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_tupl = tuple(map(float, input(
   'Enter some random tuple Elements separated by spaces = ').split()))
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in another variable.
gvn_lst = list(map(float, input(
   'Enter some random List Elements separated by spaces = ').split()))
# Give the positive number as user input using the float(input()) function and
# Store it in another variable.
gvn_positvenum=float(input("Enter some random number = "))
# Apply math. floor() function to the given positive number and print it.
print('Given positive number',gvn_positvenum,'floor value = %.2f' % math.floor(gvn_positvenum))
# # Give the negative number as user input using the float(input()) function and
# Store it in another variable.
gvn_negatvenum=float(input("Enter some random number = "))
# Apply math. floor() function to the given negative number and print it.
print('Given negative number',gvn_negatvenum,' floor value = %.2f' % math.floor(gvn_negatvenum))
# Apply math. floor() function to the given tuple element and print it.
print('Given Tuple element(gvn_tupl[0]) floor value = %.2f' % math.floor(
    gvn_tupl[0]))
# Apply math. floor() function to the given list element and print it.
print(
    'Given Tuple element(gvn_lst[3]) floor value = %.2f' % math.floor(gvn_lst[3]))

Output:

Enter some random tuple Elements separated by spaces = 26.4 10.8 -11.23 -10.7
Enter some random List Elements separated by spaces = 89 45.2 65.3 96.8
Enter some random number = 54.3
Given positive number 54.3 floor value = 54.00
Enter some random number = -10.5
Given negative number -10.5 floor value = -11.00
Given Tuple element(gvn_tupl[0]) floor value = 26.00
Given Tuple element(gvn_lst[3]) floor value = 96.00

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 floor() Function Read More »

Python Program for ceil() Function

In the previous article, we have discussed Python Program for Set discard() Method
ceil() Function in Python:

If necessary, the math.ceil() method rounds a number UP to the nearest integer and returns the result.

The ceil function in Python is used to return the smallest integer value that is greater than or equal to the specified expression or number.

Syntax:

math.ceil(number)

Parameter Values:

number: This is required. It Sets the number to round up.

Note: The ceil function returns the ceiling value if the number argument is positive or negative.
The math ceil function returns TypeError if the number argument is not a number.

Return Value: The return value is an int value that represents the rounded number.

Examples:

Example1:

Input:

Given tuple = (1.3, 10.04, -4.4, 7.7, 9.45)
Given List = [2.8, 3.4, -1.7, -6.82, 12.2]

Output:

Given positive number 9.2 ceiling value = 10.00
Given negative number -8.6 ceiling value = -8.00
Given Tuple element(gvn_tupl[3]) ceiling value = 8.00
Given Tuple element(gvn_lst[2]) ceiling value = -1.00
The Ceil of pi is:  4
Given multiple number(35+40-10.3) ceiling value  = 65.00

Example2:

Input:

Given tuple = (2.4, 85.67, 37.8, -25.5)
Given List =  [45.9, 11.32, -25, 6, 12.8, -10]

Output:

Given positive number 30.1 ceiling value = 31.00
Given negative number -20.4 ceiling value = -20.00
Given Tuple element(gvn_tupl[0]) ceiling value = 3.00
Given Tuple element(gvn_lst[3]) ceiling value = 6.00
The Ceil of pi is:  4
Given multiple number (23-10+5) ceiling value  = 18.00

Program for ceil() Function in Python

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

Approach:

  • Import math module using the import keyword.
  • Give the tuple as static input and store it in a variable.
  • Give the list as static input and store it in another variable.
  • Apply math. ceil() function to any positive number and print it.
  • Apply math. ceil() function to any negative number and print it.
  • Apply math. ceil() function to the given tuple element and print it.
  • Apply math. ceil() function to the pi value and print it.
  • Apply math. ceil() function to any multiple numbers and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the tuple as static input and store it in a variable.
gvn_tupl = (1.3, 10.04, -4.4, 7.7, 9.45)
# Give the list as static input and store it in another variable.
gvn_lst = [2.8, 3.4, -1.7, -6.82, 12.2]
# Apply math. ceil() function to any positive number and print it.
print('Given positive number 9.2 ceiling value = %.2f' % math.ceil(9.2))
# Apply math. ceil() function to any negative number and print it.
print('Given negative number -8.6 ceiling value = %.2f' % math.ceil(-8.6))
# Apply math. ceil() function to the given tuple element and print it.
print('Given Tuple element(gvn_tupl[3]) ceiling value = %.2f' % math.ceil(
    gvn_tupl[3]))
# Apply math. ceil() function to the given list element and print it.
print(
    'Given Tuple element(gvn_lst[2]) ceiling value = %.2f' % math.ceil(gvn_lst[2]))
# Apply math. ceil() function to the pi value and print it.
print("The Ceil of pi is: ", math.ceil(math.pi))
# Apply math. ceil() function to any multiple numbers and print it.
print('Given multiple number(35+40-10.3) ceiling value  = %.2f' %
      math.ceil(35+40-10.3))

Output:

Given positive number 9.2 ceiling value = 10.00
Given negative number -8.6 ceiling value = -8.00
Given Tuple element(gvn_tupl[3]) ceiling value = 8.00
Given Tuple element(gvn_lst[2]) ceiling value = -1.00
The Ceil of pi is:  4
Given multiple number(35+40-10.3) ceiling value  = 65.00

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

Approach:

  • Import math module using the import keyword.
  • Give the tuple as user input using list(),map(),input(),and split() functions.
  • Store it in a variable.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in another variable.
  • Give the positive number as user input using the float(input()) function
  • Store it in another variable.
  • Apply math. ceil() function to the given positive number and print it.
  • Give the negative number as user input using the float(input()) function and store it in another variable.
  • Apply math. ceil() function to the given negative number and print it.
  • Apply math. ceil() function to the given tuple element and print it.
  • Apply math. ceil() 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 tuple as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_tupl = tuple(map(float, input(
   'Enter some random tuple Elements separated by spaces = ').split()))
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in another variable.
gvn_lst = list(map(float, input(
   'Enter some random List Elements separated by spaces = ').split()))
# Give the positive number as user input using the float(input()) function and
# Store it in another variable.
gvn_positvenum=float(input("Enter some random number = "))
# Apply math. ceil() function to the given positive number and print it.
print('Given positive number',gvn_positvenum,'ceiling value = %.2f' % math.ceil(gvn_positvenum))
# # Give the negative number as user input using the float(input()) function and
# Store it in another variable.
gvn_negatvenum=float(input("Enter some random number = "))
# Apply math. ceil() function to the given negative number and print it.
print('Given negative number',gvn_negatvenum,'ceiling value = %.2f' % math.ceil(gvn_negatvenum))
# Apply math. ceil() function to the given tuple element and print it.
print('Given Tuple element(gvn_tupl[0]) ceiling value = %.2f' % math.ceil(
    gvn_tupl[0]))
# Apply math. ceil() function to the given list element and print it.
print(
    'Given Tuple element(gvn_lst[3]) ceiling value = %.2f' % math.ceil(gvn_lst[3]))



Output:

Enter some random tuple Elements separated by spaces = 12.3 -11.2 6.7 4.6
Enter some random List Elements separated by spaces = 8.5 10.3 -6.4 -20.8
Enter some random number = 30.1
Given positive number 30.1 ceiling value = 31.00
Enter some random number = -20.4
Given negative number -20.4 ceiling value = -20.00
Given Tuple element(gvn_tupl[0]) ceiling value = 13.00
Given Tuple element(gvn_lst[3]) ceiling value = -20.00

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 ceil() Function Read More »

Python Program for Dictionary setdefault() Method

In the previous article, we have discussed Python Program for floor() Function
Dictionary in python :

A dictionary is a set of elements that have key-value pairs. The values in the elements are accessed using the element’s keys.

Examples:

Example1:

Input:

Given dictionary = {'hello': 25, 'this': 35, 'is': 45, 'btechgeeks': 55}

Output:

The above given dictionary is :
{'hello': 25, 'this': 35, 'is': 45, 'btechgeeks': 55}
The value at the given key hello =  25
The value at the given key btechgeeks=  55
The value at the given key good =  None
The value at the given key morning =  None

Example2:

Input:

Given dictionary = {100: 'good', 150: 'morning', 200: 'btechgeeks'}

Output:

The above given dictionary is :
{100: 'good', 150: 'morning', 200: 'btechgeeks'}
The value at the given key 200 =  btechgeeks
The value at the given key 10 =  None
The value at the given key 150 =  morning

Program for Dictionary setdefault() Method in Python

Dictionary setdefault() Function:

The Python Dictionary setdefault() function is one of several Dictionary functions that can be used to print the value at a specific key position. It prints None if there is no value at the given index.

Syntax:

dictionary.setdefault(keyname, value)

Parameter values:

Keyname: This is required.The keyname of the item from which you want to retrieve the value.

Value: This is optional. This parameter has no effect if the key exists. If the key does not exist, this value takes its place. The default value is None.

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

Approach:

  • Give the dictionary as static input by initializing it with some random values and store it in a variable.
  • Print the above-given dictionary.
  • Apply dictionary.setdefault() method to the above-given dictionary to print the value at a specific key position and print it.
  • It prints None if there is no value at the given index.
  • Similarly, do the same for the other keys and print them.
  • The Exit of Program.

Below is the implementation:

# Give the dictionary by initializing it with some random values and store it
# in a variable.
gvn_dictinry = {'hello': 25, 'this': 35, 'is': 45, 'btechgeeks': 55}
# Print the above-given dictionary.
print("The above given dictionary is :")
print(gvn_dictinry)
# Apply dictionary.setdefault() method to the above-given dictionary to print the
# value at a specific key position and print it.
# It prints None if there is no value at the given index.
print("The value at the given key hello = ",
      gvn_dictinry.setdefault('hello', None))
# similarly do the same for the other keys and print them.
print("The value at the given key btechgeeks= ",
      gvn_dictinry.setdefault('btechgeeks', None))
print("The value at the given key good = ",
      gvn_dictinry.setdefault('good', None))
print("The value at the given key morning = ",
      gvn_dictinry.setdefault('morning', None))

Output:

The above given dictionary is :
{'hello': 25, 'this': 35, 'is': 45, 'btechgeeks': 55}
The value at the given key hello =  25
The value at the given key btechgeeks=  55
The value at the given key good =  None
The value at the given key morning =  None

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

Approach:

  • Take a dictionary and initialize it with an empty dictionary using dict() or {}.
  • Give the number of keys as user input using int(input()) and store it in a variable.
  • Loop till the given number of keys using for loop.
  • Inside the for loop scan the key and value as user input using input(), split() functions, and store them in two separate variables.
  • Initialize the key with the value of the dictionary.
  • Print the above-given dictionary.
  • Give the key that you want to fetch the value as user input using the input() function and store it in another variable.
  • Apply dictionary.setdefault() method to the above-given dictionary to print the value at a specific key position and print it.
  • It prints None if there is no value at the given index.
  • Similarly, do the same for the other keys and print them.
  • The Exit of Program.

Below is the implementation:

# Take a dictionary and initialize it with an empty dictionary using dict() or {}.
gvn_dictinry = {}
# Give the number of keys as user input using int(input()) and store it in a variable.
numb_of_kys = int(
    input('Enter some random number of keys of the dictionary = '))
# Loop till the given number of keys using for loop.
for p in range(numb_of_kys):
        # Inside the for loop scan the key and value as
    # user input using input(),split() functions
    # and store them in two separate variables.
    keyy, valuee =  input(
        'Enter key and value separated by spaces = ').split()
    # Initialize the key with the value of the dictionary.
    gvn_dictinry[keyy] = valuee

# Print the above-given dictionary.
print("The above given dictionary is :")
print(gvn_dictinry)
# Give the key that you want to fetch the value as user input using the input()
# function and store it in another variable.
gvn_key1 = input("Enter some random number = ")
# Apply dictionary.setdefault() method to the above-given dictionary to print the
# value at a given specific key position and print it.
# It prints None if there is no value at the given index.
print("The value at the given key", gvn_key1, " = ",
      gvn_dictinry.setdefault(gvn_key1, None))
# similarly do the same for the other keys and print them.
gvn_key2 = input("Enter some random number = ")
print("The value at the given key", gvn_key2, " = ",
      gvn_dictinry.setdefault(gvn_key2, None))

Output:

Enter some random number of keys of the dictionary = 3
Enter key and value separated by spaces = 20 good
Enter key and value separated by spaces = 40 morning
Enter key and value separated by spaces = 60 btechgeeks
The above given dictionary is :
{'20': 'good', '40': 'morning', '60': 'btechgeeks'}
Enter some random number = 40
The value at the given key 40 = morning
Enter some random number = 100
The value at the given key 100 = None

Learn several Python Dictionary Method Examples on our page and access the dictionary items easily.

Python Program for Dictionary setdefault() Method Read More »

Python Program for fabs() Function

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

The math. fabs() method returns a float containing the absolute value of a number.

The term absolute refers to a non-negative number. If the value has a negative sign, this removes it.

This method, unlike Python abs(), always converts the value to a float value.

Syntax:

math.fabs(x)

Parameters:

x: This is required. It is a number. If we try anything other than a number, we get a TypeError.

Return Value: It returns a float value which represents the absolute value of x.

Examples:

Example1:

Input:

Given list = [1, -2, -3, 4]
Given first number = 45
Given second number = -70

Output:

The absolute value of above given number 45  =  45.0
The absolute value of above given number -70  =  70.0
The absolute value of given list element gvnlst[2] =  3.0

Example2:

Input:

Given list = [86, 34, 20, 10]
Given first number = 90
Given second number = -40

Output:

The absolute value of above given number 90  =  90.0
The absolute value of above given number -40  =  40.0
The absolute value of given list element gvnlst[1] =  34.0

Program for fabs() 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 number as static input and store it in another variable.
  • Apply math.fabs() function to the given number to get the absolute value of the given number as float and print it.
  • Similarly, do the same for the other number.
  • Apply math.fabs() 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, -2, -3, 4]
# Give the number as static input and store it in another variable.
gvn_numb1 = 45
# Apply math.fabs() function to the given number to get the absolute value of
# the given number as float and print it.
print("The absolute value of above given number",
      gvn_numb1, " = ", math.fabs(gvn_numb1))
# similarly do the same for the other number.
gvn_numb2 = -70
print("The absolute value of above given number",
      gvn_numb2, " = ", math.fabs(gvn_numb2))
# Apply math.fabs() function to the given list element and print it.
print(
    "The absolute value of given list element gvnlst[2] = ", math.fabs(gvn_lst[2]))

Output:

The absolute value of above given number 45  =  45.0
The absolute value of above given number -70  =  70.0
The absolute value of given list element gvnlst[2] =  3.0

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 number as user input using the int(input()) function and store it in a variable.
  • Apply math.fabs() function to the given first number to get the absolute value of the given number as float and print it.
  • Similarly, do the same for the other number.
  • Apply math.fabs() 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 number as user input using the int(input()) function and store it in a variable.
gvn_numb1= int(input("Enter some random number = "))
# Apply math.fabs() function to the given first number to get the absolute value of
# the given number as float and print it.
print("The absolute value of above given number",
      gvn_numb1, " = ", math.fabs(gvn_numb1))
# similarly do the same for the other number.
gvn_numb2 = int(input("Enter some random number = "))
print("The absolute value of above given number",
      gvn_numb2, " = ", math.fabs(gvn_numb2))
# Apply math.fabs() function to the given list element and print it.
print(
    "The absolute value of given list element gvnlst[1] = ", math.fabs(gvn_lst[1]))

Output:

Enter some random List Elements separated by spaces = 86 34 20 10
Enter some random number = 90
The absolute value of above given number 90 = 90.0
Enter some random number = -40
The absolute value of above given number -40 = 40.0
The absolute value of given list element gvnlst[1] = 34.0

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 fabs() Function Read More »

Python Program for copysign() Function

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

The math.copysign() method returns a float containing the first parameter’s value and the sign (+/-) of the second parameter.

Syntax:

math.copysign(x, y)

Parameter Values:

x: This is required. It is a number. It returns the value of this parameter.

y: This is required. It is a number. It returns the sign(+/-) of this parameter.

For example:

let x=10, y=-20.5

The math.copysign() method returns the value of x=10, and the sign of y i.e,negative sign(-).

so, the result number = -10

Examples:

Example1:

Input:

Given tuple = (1, -10, 20, 35, -12.5)
Given List = [6.7, 80, -10, -26, 13.5]

Output:

The copysign value of given numbers 12 and -10 =  -12.0
The copysign value of given numbers -9.5 and 30 =  9.5
The copysign value of given tuple element gvn_tupl[1] and 50 =  10.0
The copysign value of given list element gvn_lst[2] and -65 =  -10.0

Example2:

Input:

Given tuple = (10, -20, 30, -40, 50)
Given List = [1, -2, -3, 4]

Output:

The copysign value of given numbers 45 and -70 =  -45.0
The copysign value of given numbers -80 and 100 =  80.0
The copysign value of given tuple element gvn_tupl[0] and -25 =  -10.0
The copysign value of given list element gvn_lst[3] and 54 =  4.0

Program for copysign() Function in python

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

Approach:

  • Import math module using the import keyword.
  • Give the tuple as static input and store it in a variable.
  • Give the list as static input and store it in another variable.
  • Apply math. copysign() function to any positive and negative numbers respectively and print it.
  • Apply math. copysign() function to any negative and positive numbers respectively and print it.
  • Apply math. copysign() function to the given tuple element, any other number and print it.
  • Apply math. copysign() function to the given list element, any other number and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the tuple as static input and store it in a variable.
gvn_tupl = (1, -10, 20, 35, -12.5)
# Give the list as static input and store it in another variable.
gvn_lst = [6.7, 80, -10, -26, 13.5]
# Apply math. copysign() function to any positive and negative numbers
# respectively and print it.
print('The copysign value of given numbers 12 and -10 = ', math.copysign(12, -10))
# Apply math. copysign() function to any negative and positive numbers
# respectively and print it.
print('The copysign value of given numbers -9.5 and 30 = ', math.copysign(-9.5, 30))
# Apply math. copysign() function to the given tuple element, any other number
# and print it.
print('The copysign value of given tuple element gvn_tupl[1] and 50 = ', math.copysign(
    gvn_tupl[1], 50))
# Apply math. copysign() function to the given list element, any other
# number and print it.
print('The copysign value of given list element gvn_lst[2] and -65 = ', math.copysign(
    gvn_lst[2], -65))

Output:

The copysign value of given numbers 12 and -10 =  -12.0
The copysign value of given numbers -9.5 and 30 =  9.5
The copysign value of given tuple element gvn_tupl[1] and 50 =  10.0
The copysign value of given list element gvn_lst[2] and -65 =  -10.0

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

Approach:

  • Import math module using the import keyword.
  • Give the tuple as user input using list(),map(),input(),and split() functions.
  • Store it in a variable.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in another variable.
  • Give positive and negative numbers respectively as user input using float(), map(), input(), and split() functions and store them in two separate variables.
  • Apply math. copysign() function to the given positive and negative numbers respectively and print it.
  • Give negative and positive numbers respectively as user input using float(), map(), input(), and split() functions and store them in two separate variables.
  • Apply math. copysign() function to the given negative and positive numbers respectively and print it.
  • Give the number as user input using the float(input()) function and store it in another variable.
  • Apply math. copysign() function to the given tuple element, and above-given number and print it.
  • Give the number as user input using the float(input()) function and store it in another variable.
  • Apply math. copysign() 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 tuple as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_tupl = tuple(map(float, input(
   'Enter some random tuple Elements separated by spaces = ').split()))
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in another variable.
gvn_lst = list(map(float, input(
   'Enter some random List Elements separated by spaces = ').split()))
# Give positive and negative numbers respectively as user input using float(),map(),input(),and split()
# functions and store them in two separate variables.
a,b=map(float,input("Enter some random positive and negative numbers separated by spaces = ").split())
# Apply math. copysign() function to the given positive and negative numbers respectively and print it.
print("The copysign value of given numbers",a,"and",b," = ", math.copysign(a, b))
# Give negative and positive numbers respectively as user input using float(),map(),input(),and split()
# functions and store them in two separate variables.
p,q=map(float,input("Enter some random negative and positive numbers separated by spaces = ").split())
# Apply math. copysign() function to the given negative and positive numbers respectively and print it.
print("The copysign value of given numbers",p,"and",q," = ", math.copysign(p, q))
#Give the number as user input using the float(input()) function and store it in another variable.
gvn_numb1= float(input("Enter some random number = "))
#Apply math. copysign() function to the given tuple element, and above-given number and print it.
print('The copysign value of given tuple element gvn_tupl[0] and',gvn_numb1,' = ', math.copysign(
    gvn_tupl[0],gvn_numb1 ))
#Give the number as user input using the float(input()) function and store it in another variable.
gvn_numb2= float(input("Enter some random number = "))
#Apply math. copysign() function to the given list element, and above-given number and print it.
print('The copysign value of given list element gvn_lst[2] and',gvn_numb2,' = ', math.copysign(
    gvn_lst[2],gvn_numb2 ))

Output:

Enter some random tuple Elements separated by spaces = 20 -34 45 -64
Enter some random List Elements separated by spaces = 16 -31 -78 42
Enter some random positive and negative numbers separated by spaces = 25 -15
The copysign value of given numbers 25.0 and -15.0 = -25.0
Enter some random negative and positive numbers separated by spaces = -18 46
The copysign value of given numbers -18.0 and 46.0 = 18.0
Enter some random number = 65
The copysign value of given tuple element gvn_tupl[0] and 65.0 = 20.0
Enter some random number = -17
The copysign value of given list element gvn_lst[2] and -17.0 = -78.0

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 copysign() Function Read More »

Python Program for fsum() Function

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

The math.fsum() method returns the sum of all iterable items (tuples, arrays, lists, etc.).

Syntax:

math.fsum(iterable)

Parameters:

iterable: This is required. It may be a tuple, list, arrays, etc to sum. If the iterable does not contain numbers, it throws a TypeError.

Return Value:

It returns a float value representing the sum of the iterable’s items.

Examples:

Example1:

Input:

Given List = [1, 3, 5, 8]
Given Tuple = (10, 20, 50, 60)

Output:

The sum of all list items after applying fsum() function =  17.0
The sum of all tuple items after applying fsum() function =  140.0

Example2:

Input:

Given List = [15, 20, 40, 10, 30]
Given Tuple = (45, 30, 10, 5, 6)

Output:

The sum of all list items after applying fsum() function =  115.0
The sum of all tuple items after applying fsum() function =  96.0

Program for fsum() 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 tuple as static input and store it in another variable.
  • Apply math.fsum() function to the given list to get the sum of all list items.
  • Store it in another variable.
  • Print the above result list sum.
  • Apply math.fsum() function to the given tuple to get the sum of all tuple items.
  • Store it in another variable.
  • Print the above result tuple sum.
  • 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, 5, 8]
# Give the tuple as static input and store it in another variable.
gvn_tupl = (10, 20, 50, 60)
# Apply math.fsum() function to the given list to get the sum of all list items.
# store it in another variable.
lst_sum = math.fsum(gvn_lst)
# print the above result list sum.
print("The sum of all list items after applying fsum() function = ", lst_sum)
# Apply math.fsum() function to the given tuple to get the sum of all tuple items.
# store it in another variable.
tupl_sum = math.fsum(gvn_tupl)
# print the above result tuple sum.
print("The sum of all tuple items after applying fsum() function = ", tupl_sum)

Output:

The sum all list items after applying fsum() function =  17.0
The sum all tuple items after applying fsum() function =  140.0

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 tuple as user input using list(),map(),input(),and split() functions.
  • Store it in another variable.
  • Apply math.fsum() function to the given list to get the sum of all list items.
  • Store it in another variable.
  • Print the above result list sum.
  • Apply math.fsum() function to the given tuple to get the sum of all tuple items.
  • Store it in another variable.
  • Print the above result tuple sum.
  • 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 the tuple as user input using list(),map(),input(),and split() functions.
# Store it in another variable.
gvn_tupl = tuple(map(int, input(
   'Enter some random tuple Elements separated by spaces = ').split()))
# Apply math.fsum() function to the given list to get the sum of all list items.
# store it in another variable.
lst_sum = math.fsum(gvn_lst)
# print the above result list sum.
print("The sum of all list items after applying fsum() function = ", lst_sum)
# Apply math.fsum() function to the given tuple to get the sum of all tuple items.
# store it in another variable.
tupl_sum = math.fsum(gvn_tupl)
# print the above result tuple sum.
print("The sum of all tuple items after applying fsum() function = ", tupl_sum)

Output:

Enter some random List Elements separated by spaces = 15 20 40 10 30
Enter some random tuple Elements separated by spaces = 45 30 10 5 6
The sum of all list items after applying fsum() function = 115.0
The sum of all tuple items after applying fsum() function = 96.0

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 fsum() Function Read More »

How to Find Cube Root in Python

In the previous article, we have discussed Python Program for isfinite() Function
Given a number and the task is to calculate the cube root of a given number in Python.

Cube root:

A cube root is a number that, when cubed, yields a given number. A number’s cube root is a value that, when multiplied by itself three times, yields the original value.

‘3√’ represents the cube root symbol. In the case of square root, we simply used the root symbol, such as ‘√’, which is also known as a radical.

For example :

The cube root of 27 is 3. (3*3*3=27)

Cube root of a Negative Number:

We cannot find the cube root of negative numbers using the method described above. The cube root of integer -27, for example, should be -3, but Python returns 1.5000000000000004+2.598076211353316j.

To calculate the cube root of a negative number in Python, first, use the abs() function, and then use the simple math equation.

Examples:

Example1:

Input:

Given Number = 125

Output:

The cube root of the given number { 125 } =  4.999999999999999

Example2:

Input:

Given Number = -27

Output:

The cube root of the given number { -27 } = -3.0

Program for How To Find Cube Root in Python

Below are the ways to calculate the cube root of a given number in python:

Method #1: Using Power Operator (Static Input)

Approach:

  • Give the number as static input and store it in a variable.
  • Check if the given is less than 0 or not using the if conditional statement.
  • If it is true, then get the absolute value of the given number using the abs() function and store it in another variable.
  • Calculate the value of a given number raised to the power (1/3) and multiplied with -1 to get the cube root of the given number.
  • Store it in another variable say rslt_cuberoott.
  • Else, calculate the value of a given number raised to the power (1/3) to get the cube root of the given number.
  • Store it in the same variable say rslt_cuberoott.
  • Print the cube root of the given number
  • The Exit of Program.

Below is the implementation:

# Give the number as static input and store it in a variable.
gvn_numb = 125
# Check if the given is less than 0 or not using the if conditional statement.
if gvn_numb < 0:
    # If it is true, then get the absolute value of the given number using the
    # abs() function and store it in the another variable.
    abs_numbr = abs(gvn_numb)
    # Calculate the value of the given number raised to the power (1/3) and
    # multiplied with -1 to get the cube root of the given number.
    # Store it in another variable say rslt_cuberoott.
    rslt_cuberoott = abs_numbr**(1/3)*(-1)
else:
    # Else, calculate the value of a given number raised to the power (1/3) to
    # get the cube root of the given number.
    # Store it in the same variable say rslt_cuberoott.
    rslt_cuberoott = gvn_numb**(1/3)
# Print the cube root of the given number
print("The cube root of the given number {", gvn_numb, "} = ", rslt_cuberoott)

Output:

The cube root of the given number { 125 } =  4.999999999999999

Method #2: Using Power Operator (User Input)

Approach:

  • Give the number as user input using the int(input()) function and store it in a variable.
  • Check if the given is less than 0 or not using the if conditional statement.
  • If it is true, then get the absolute value of the given number using the abs() function and store it in another variable.
  • Calculate the value of a given number raised to the power (1/3) and multiplied with -1 to get the cube root of the given number.
  • Store it in another variable say rslt_cuberoott.
  • Else, calculate the value of a given number raised to the power (1/3) to get the cube root of the given number.
  • Store it in the same variable say rslt_cuberoott.
  • Print the cube root of the given number
  • The Exit of Program.

Below is the implementation:

# Give the number as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some random number = "))
# Check if the given is less than 0 or not using the if conditional statement.
if gvn_numb < 0:
    # If it is true, then get the absolute value of the given number using the
    # abs() function and store it in the another variable.
    abs_numbr = abs(gvn_numb)
    # Calculate the value of the given number raised to the power (1/3) and
    # multiplied with -1 to get the cube root of the given number.
    # Store it in another variable say rslt_cuberoott.
    rslt_cuberoott = abs_numbr**(1/3)*(-1)
else:
    # Else, calculate the value of a given number raised to the power (1/3) to
    # get the cube root of the given number.
    # Store it in the same variable say rslt_cuberoott.
    rslt_cuberoott = gvn_numb**(1/3)
# Print the cube root of the given number
print("The cube root of the given number {", gvn_numb, "} = ", rslt_cuberoott)

Output:

Enter some random number = -27
The cube root of the given number { -27 } = -3.0

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.

How to Find Cube Root in Python Read More »

Python Program for isfinite() Function

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

The math.isfinite() method determines whether or not a number is finite.

If the specified number is a finite number, this method returns true; otherwise, it returns False.

Syntax:

math.isfinite(value)

Parameters:

Value: This is required. The value to be checked. A number (float/integer/infinite/NaN/finite) must be specified.

Return Value: It returns a boolean value. Returns True if x is finite and False if x is infinity or NaN.

Examples:

Example1:

Input:

Given Number = 20
Given number = -100
Given Number = math.pi
Given value = NaN
Given value = inf

Output:

Checking if the above given number 20 is finite or not : True
True
True
False
False

Example2:

Input:

Given Number = 10000
Given value = -math.inf
Given value = nan

Output:

Checking if the above given number 10000 is finite or not : True
False
False

Program for isfinite() Function 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.
  • Apply math.isfinite() function to the given number to check if the given number is finite or not.
  • Store it in another variable.
  • Print the above result.
  • Similarly, check for the other values and print the result.
  • The Exit of 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 = 20
# Apply math.isfinite() function to the given number to check if the given number
# is finite or not.
# Store it in another variable.
rslt = math.isfinite(gvn_numb)
# print the above result.
print("Checking if the above given number",
      gvn_numb, "is finite or not :", rslt)
# similarly check for the other values 
print(math.isfinite(-100))
print(math.isfinite(math.pi))
print(math.isfinite(float('NaN')))
print(math.isfinite(float('inf')))

Output:

Checking if the above given number 20 is finite or not : True
True
True
False
False

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

Approach:

  • Import math module using the import keyword.
  • Give the number as user input using the int(input()) function and store it in a variable.
  • Apply math.isfinite() function to the given number to check if the given number is finite or not.
  • Store it in another variable.
  • Print the above result.
  • Similarly, check for the other values and print the result.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the number as user input using the int(input()) function and store it in a variable.
gvn_numb = int(input('Enter some random number = '))
# Apply math.isfinite() function to the given number to check if the given number
# is finite or not.
# Store it in another variable.
rslt = math.isfinite(gvn_numb)
# print the above result.
print("Checking if the above given number",
      gvn_numb, "is finite or not :", rslt)
# similarly check for the other numbers
b = int(input('Enter some random number = '))
print(math.isfinite(b))

Output:

Enter some random number = -1000
Checking if the above given number -1000 is finite or not : True
Enter some random number = -19999
True

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 isfinite() Function Read More »

Python Program for fmod() Function

In the previous article, we have discussed Python Program for Dictionary setdefault() Method
fmod() Function in Python:

The remainder (modulo) of x/y is returned by the math.fmod() method.

The Python fmod() math function is used to compute the Modulo of the given arguments.

Syntax:

math.fmod(x, y)

Parameters:

x: This is required. It is a positive or a negative number to divide.

y: This is required. It is a positive or negative number with which to divide x

Note:

If both x and y are zero, a ValueError is returned.
If y = 0, a ValueError is returned.
If x or y is not a number, it returns a TypeError.

Return Value:

It returns a float value which indicates the remainder of x/y.

Examples:

Example1:

Input:

Given list = [1, -2, -3, 4]
Given first number = 18 
Given second number = 2
Given number = 3

Output:

The remainder when given first number/second number { 18 / 2 } =  0.0
The remainder when gvn_lst[2]/given number { -3 / 5 } =  -3.0
The remainder of -16/5 =  -1.0

Example2:

Input:

Given list = [2, 4, 6, 8, 10]
Given first number =  8
Given second number =  5
Given number = 4

Output:

The remainder when given first number/second number { 8 / 5 } =  3.0
The remainder when gvn_lst[3]/given number { 8 / 4 } =  0.0
The remainder of -25/-4 =  -1.0

Program for fmod() 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.fmod() function to the given first and the second number to get the remainder of the given first number/given the second number.
  • Store it in another variable.
  • Print the above result which is the result after applying fmod() function.
  • Give the number as static input and store it in another variable.
  • Apply math.fmod() 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, -3, 4]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 18
# Give the second number as static input and store it in another variable.
gvn_numb2 = 2
# Apply math.fmod() function to the given first and second number to get the
# remainder of given first number/given second number.
# store it in another variable.
remaindr = math.fmod(gvn_numb1, gvn_numb2)
# Print the above result which is the result after applying fmod() function.
print(
    "The remainder when given first number/second number {", gvn_numb1, "/", gvn_numb2, "} = ", remaindr)
# Give the number as static input and store it in another variable.
gvn_numb3 = 5
# Apply math.fmod() function to the given list element and above given number and print it.
print(
    "The remainder when gvn_lst[2]/given number {", gvn_lst[2], "/", gvn_numb3, "} = ", math.fmod(gvn_lst[2], gvn_numb3))
# similarly do the same for other numbers and print it.
print("The remainder of -16/5 = ", math.fmod(-16, 5))

Output:

The remainder when given first number/second number { 18 / 2 } =  0.0
The remainder when gvn_lst[2]/given number { -3 / 5 } =  -3.0
The remainder of -16/5 =  -1.0

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.fmod() function to the given first and the second number to get the remainder of the given first number/given the second number.
  • Store it in another variable.
  • Print the above result which is the result after applying fmod() function.
  • Give the number as user input using the int(input()) function and store it in another variable.
  • Apply math.fmod() 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 and store them in two separate variables.
gvn_numb1, gvn_numb2 = map(int, input(
    "Enter two random numbers separated by spaces = ").split())
# Apply math.fmod() function to the given first and second number to get the
# remainder of given first number/given second number.
# store it in another variable.
remaindr = math.fmod(gvn_numb1, gvn_numb2)
# Print the above result which is the result after applying fmod() function.
print(
    "The remainder when given first number/second number {", gvn_numb1, "/", gvn_numb2, "} = ", remaindr)
# 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.fmod() function to the given list element and above given number and print it.
print(
    "The remainder when gvn_lst[3]/given number {", gvn_lst[3], "/", gvn_numb3, "} = ", math.fmod(gvn_lst[3], gvn_numb3))

Output:

Enter some random List Elements separated by spaces = 2 4 6 8 10
Enter two random numbers separated by spaces = 8 5
The remainder when given first number/second number { 8 / 5 } = 3.0
Enter some random number = 4 
The remainder when gvn_lst[3]/given number { 8 / 4 } = 0.0

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 fmod() Function Read More »

Python Program for frexp() Function

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

The mantissa and exponent of a given number are returned as a pair by the math.frexp() method (m,e).

This method’s mathematical formula:  m * (2**e)

Syntax:

math.frexp(number)

Parameters:

number: This is required. A number that is either positive or negative. If the value is not a number, TypeError is returned.

Return Value:

A pair of tuple values representing the mantissa and exponent of x. (m,e). The mantissa is returned as a float, and the exponent is returned as an integer.

The Python frexp() function returns the mantissa and exponent of x as a pair if the number argument is positive or negative (m, e).

The Python frexp() function returns TypeError if the number argument is not a number.

Tip:  We can easily find the Number value by taking the opposite approach, and

The formula is: Number = m * 2**e. The first argument is m, and the second argument is e.

Examples:

Example1:

Input:

Given list = [2, 4, 6, 8, 10]
Given first number = 5
Given second number = -3

Output:

The result after applying frexp() function on above given first number 5  =  (0.625, 3)
The result after applying frexp() function on above given second number -3  =  (-0.75, 2)
The result after applying frexp() function on given list element gvnlst[1] =  (0.5, 3)

Example2:

Input:

Given list = [4, 6, -7, -9]
Given first number = 8
Given second number = 2

Output:

The result after applying frexp() function on above given first number 8  =  (0.5, 4)
The result after applying frexp() function on above given second number 2  =  (0.5, 2)
The result after applying frexp() function on given list element gvnlst[3] =  (-0.5625, 4)

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

Output:

The result after applying frexp() function on above given first number 5  =  (0.625, 3)
The result after applying frexp() function on above given second number -3  =  (-0.75, 2)
The result after applying frexp() function on given list element gvnlst[1] =  (0.5, 3)

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 int(input()) function and store it in a variable.
  • Apply math.frexp() function to the given first number to get the mantissa and exponent of a given number and print it.
  • Similarly, do the same for the other number.
  • Apply math.frexp() 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 int(input()) function
# and store it in a variable.
gvn_numb1 = int(input("Enter some random number = "))
# Apply math.frexp() function to the given first number to get the mantissa
# and exponent of a given number and print it.
print("The result after applying frexp() function on above given first number",
      gvn_numb1, " = ", math.frexp(gvn_numb1))
# similarly do the same for the other number.
gvn_numb2 = int(input("Enter some random number = "))
print("The result after applying frexp() function on above given second number",
      gvn_numb2, " = ", math.frexp(gvn_numb2))
# Apply math.frexp() function to the given list element and print it.
print(
    "The result after applying frexp() function on given list element gvnlst[3] = ", math.frexp(gvn_lst[3]))

Output:

Enter some random List Elements separated by spaces = 4 6 -7 -9
Enter some random number = 8
The result after applying frexp() function on above given first number 8 = (0.5, 4)
Enter some random number = 2
The result after applying frexp() function on above given second number 2 = (0.5, 2)
The result after applying frexp() function on given list element gvnlst[3] = (-0.5625, 4)

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 frexp() Function Read More »