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
|
|
|
|
"""
|
2019-10-08 08:24:01 +00:00
|
|
|
return -num if num < 0 else 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
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
if __name__ == "__main__":
|
2018-11-03 20:08:13 +00:00
|
|
|
main()
|