Write a program to print the absolute difference between the two given numbers. (Absolute difference is the difference without the negative sign)
#function to return the Absolute difference
def absDiff(a,b):
return abs(a)-abs(b)
#test runs
print(absDiff(-1,3)) #-2
print(absDiff(-1,-3)) #-2
print(absDiff(1,3)) #-2
print(absDiff(-5,3)) #2
Comments
Dear v Viswanath post a new task
this program will be better a=int(input()) b=int(input()) c= a-b d=abs(c) print(d)
Dear Alok please post a new question
if the given N1 is 200 and N2 is 500 The difference in number is 200 - 500 = -300 The absolute difference is 300. Sample Input 200 500 Sample Output 300 Sample Input -12 -1 Sample Output 11 How this will come
Leave a comment