Python Program to Find Out Absolute Value

Python program to find out absolute value; Through this tutorial, i am going to show you how to write a program to find out absolute value of an input number in python.

Python Program to Find Out Absolute Value

Python abs() is a standard builtin python function, which is used to returns the absolute value of the given number. If the number is complex, the abs() method returns its magnitude. 

Python absolute Syntax

Python abs() method syntax is the following:

abs(n)

Here, n is the required parameter, and it is the number.

The abs() method will returns the absolute value of the given number.

  1. For integers – absolute integer value is returned
  2. For floating numbers – floating absolute value is returned
  3. For complex numbers – the magnitude of the number is returned

See the first example of python abs() function following:

x = abs(-19.21)
print(x)

Output

19.21

Python program to find out the absolute value of an input number in python

  • Use a python input() function in your python program that allows the user to enter any number.
  • Convert the user inputted number into absolute numbers using the abs () function.
  • End of python program, Print the result
#program to find out absolute value of an input number in python
num = int(input(" Please Enter the number : "))
abs = abs(num)
print("The absolute value of given number is : ", abs)

Output

Please Enter the number :  -5 
The absolute value of given number is :  5 

Recommended Python Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.