Create a function to return the absolute the given value in Python

Here, we are going to learn to create a function to return the absolute the given value in Python programming language.
Submitted by IncludeHelp, on March 02, 2020

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))

Output

101
202
10.23
34.560.34
0.45

Python Basic Programs »



Related Programs

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.