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
- Take a number as input through the user.
- Using an if-else statement check whether the input number is positive or negative.
- If the number is negative print its absolute value by using abs(),else print the number.
- 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