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