Program to print the absolute value of a number

In this python if else program, we will print the absolute value of a number. If the number is negative then print its absolute value, else print the number.

Absolute value: The absolute value of a real number a is the non-negative value of a without regard to its sign.

Steps to solve the program
  1. Take a number as input through the user.
  2. Using an if-else statement check whether the input number is positive or negative.
  3. If the number is negative print its absolute value by using abs(),else print the number.
  4. Print the output.
				
					num = int(input("Enter a number: "))

if num<0:
    print("Absolute value of the number: ",abs(num))
else:
    print("Absolute value of the number: ",num)
				
			

Output :

				
					Enter a number: -1
Absolute value of the number:  1
				
			

Related Articles

Calculate the discount based on the bill.

check the student’s eligibility to attend the exam based on his/her attendance.

Leave a Comment