Calculating absolute value in Python

前端 未结 1 1965
我在风中等你
我在风中等你 2021-01-15 02:30

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

1条回答
  •  青春惊慌失措
    2021-01-15 03:24

    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
    

    0 讨论(0)
提交回复
热议问题