In the below program – we are creating a function named get_absolute_value(), it accepts a number and returns the absolute value of the given number.
"""
function to return the
absolute the given value in Python
"""
def get_absolute_value(n):
if n >= 0:
return n
else:
return -n
# main code
print(get_absolute_value(101))
print(get_absolute_value(-202))
print(get_absolute_value(10.23))
print(get_absolute_value(-34.56))
print(get_absolute_value(0.34))
print(get_absolute_value(-0.45))
In the below program – we are creating a function named get_absolute_value(), it accepts a number and returns the absolute value of the given number.
Output
need an explanation for this answer? contact us directly to get an explanation for this answer