Reputation: 115
How do I make a program that asks for one floating point number in Python and then calculates the absolute value? I've already tried the asking, but I can't make the line where it calculates the absolute value.
Upvotes: 8
Views: 19520
Reputation: 1769
You wanted to calculate the absolute value using python. Here Im providing the code:
Python code function: abs(Number)
Python code example: abs(-100)
Python code example: abs(105-20)
Python code example: abs(100-200)
Upvotes: 0
Reputation:
You can do it with the built-in abs()
function:
absolute_val = abs(x)
Otherwise, without the built-in function, use math:
absolute_val = (x ** 2) ** 0.5
Upvotes: 25