Home » Python Difference Between Two Numbers

# Python Difference Between Two Numbers

Learn about Python Difference Between Two Numbers in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

#### Python Difference Between Two Numbers

The below code gives the absolute difference between two numbers given by the user.

``````# Python program to find difference between two numbers

# inputs
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))

# num1 is greater than num2
if num1 > num2:
diff = num1 - num2
# num1 is less than num2
else:
diff = num2 - num1

# print difference value
print('The difference between numbers = %0.2f' %diff)``````

Output:

```Enter first number: 4
Enter second number: 2
The difference between numbers = 2.00```

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Factorial Program in Python using Function