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. 回答1: 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 来源: https://stackoverflow.com/questions/32540121/calculating-absolute-value-in-python