K.Kane
K.Kane

Reputation: 115

Calculating absolute value in Python

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

Answers (2)

MD. SHIFULLAH
MD. SHIFULLAH

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)

Output: enter image description here

Upvotes: 0

user3917838
user3917838

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

Related Questions