Calculating absolute value in Python

橙三吉。 提交于 2021-02-04 19:26:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!