Find the absolute value of a number entered through the keyboard


This program is a basic implementation of a program that finds the absolute value of a given number. The program first prompts the user to input a number using the "input" function, and then converts the input string to an integer using the "int" function. The absolute value of a number is the positive value of the number, regardless of whether it's positive or negative.

The program then uses an "if" statement to check if the number is less than 0, if the number is less than zero, it multiples the number with -1 and assigns it back to the same variable num. This way the negative number gets converted to positive. Finally, the program prints the absolute value of the input number using the "print" function.

This program will work for any negative number as well as positive numbers, as the absolute value of a positive number is the number itself and the absolute value of a negative number is the positive version of that number.

Source Code

num = int(input("Enter the Number :"))
#print("Absolute Number :",abs(num))
if(num<0):
	num = (-1)*num
print("Absolute Number :",num)
 

Output

Enter the Number :-34
Absolute Number : 34


Example Programs