Write a function abs def absn Double Double that returns the
Write a function abs def abs(n: Double): Double that returns the absolute value of n. This a function that takes a value of type Double and returns a value of type Double. This function corresponds to the JavaScript library function Math.abs.
Solution
PROGRAM CODE:
def abs(n):
if(n < 0):
return 0 - n
else:
return n
print(abs(-21.0))
print(abs(32.0))
OUTPUT:
