2019-07-01 08:10:18 +00:00
|
|
|
"""Absolute Value."""
|
|
|
|
|
|
|
|
|
2019-07-10 20:09:24 +00:00
|
|
|
def abs_val(num):
|
2018-11-03 20:08:13 +00:00
|
|
|
"""
|
2019-07-01 08:10:18 +00:00
|
|
|
Find the absolute value of a number.
|
|
|
|
|
2019-07-10 20:09:24 +00:00
|
|
|
>>abs_val(-5)
|
2018-11-03 20:08:13 +00:00
|
|
|
5
|
2019-07-10 20:09:24 +00:00
|
|
|
>>abs_val(0)
|
2018-11-03 20:08:13 +00:00
|
|
|
0
|
|
|
|
"""
|
|
|
|
if num < 0:
|
|
|
|
return -num
|
2019-07-10 20:09:24 +00:00
|
|
|
|
|
|
|
# Returns if number is not < 0
|
|
|
|
return num
|
2018-11-03 20:08:13 +00:00
|
|
|
|
2019-07-01 08:10:18 +00:00
|
|
|
|
2018-11-03 20:08:13 +00:00
|
|
|
def main():
|
2019-07-01 08:10:18 +00:00
|
|
|
"""Print absolute value of -34."""
|
2019-07-10 20:09:24 +00:00
|
|
|
print(abs_val(-34)) # = 34
|
2019-07-01 08:10:18 +00:00
|
|
|
|
2018-11-03 20:08:13 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|