Write a Program to Find Out Absolute Value of an Input Number in Python

Write a Program to Find Out Absolute Value of an Input Number in Python

Hi, in this blog lets try to solve how to get an absolute value of given number in python programming language.

 

Write a Program to Find Out Absolute Value of an Input Number in Python

 

 

Given the negative or positive number for example - 14 or  + 14 The absolute value of any negative number or a positive number is just a number for example in the above -14, +14 the value will be just a number that is a 14 is a absolute value of a given number

Let's take a variable number and ask user to enter the number and convert it to integer type using int() Function call.  the user enters an integer so it will be stored in the variable number and now let's use abs() function  to convert the number to its absolute value.

abs() function takes an argument as a number either a positive or negative and  returns the absolute value number. Let's tour this absolute value into another variable abs_value. Once we get the absolute value print the absolute value as a output  using print function call


Python Program to Find Out Absolute Value of an Input Number 

number = int(input("Enter a Number : "))
abs_number = abs(number)
print("Absolute Value o Number is : ", abs_number)


OUTPUT: 

Enter a Number : -14
Absolute Value of Number is :  14
 

Conclusion : Try running the program by yourself, comment down if any queries.



Post a Comment

0 Comments