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:

 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site