Write a Python program to calculate the absolute value of a floating point number


This is a simple Python program that uses the math module to compute the absolute value of different numbers. The math.fabs() function is used to calculate the absolute value of a number. The function takes a single argument, which can be an integer or a floating-point number. It returns the absolute value of the input value.

In this program, the math.fabs() function is called four times with different input values to calculate their absolute values. The absolute values of -45.56, 23.7, 0.1, and -0.7 are computed and printed to the console using the print() function.

Source Code

import math
print("Absolute Values :",math.fabs(-45.56))
print("Absolute Values :",math.fabs(23.7))
print("Absolute Values :",math.fabs(0.1))
print("Absolute Values :",math.fabs(-0.7))

Output

Absolute Values : 45.56
Absolute Values : 23.7
Absolute Values : 0.1
Absolute Values : 0.7

Example Programs