108k views
4 votes
Write a python function absDiff(...) that takes two integers as parameters, gets the absolute value of both, subtracts the second from the first, and returns the difference.

1 Answer

4 votes

Step-by-step explanation:

Remember, an absolute value is the non-negative value of a number in this case the integer.

First, using the abs() function. Here's an example:

# Some random integers

variableA = -308

variableB = 301

Second, # Get the absolute values of those integers

absA = abs(variableA)

absB = abs(variableB)

Next,

# Output the results

print("Absolute values of integers with `abs()`:")

print("|", variableA, "| = ", absA, sep="")

Finally,

Use abs(variableA-variableB):

In [1]: abs(-308-301)

Out[1]: 307

User Paul Collingwood
by
6.5k points