Python/Maths/absMin.py

21 lines
309 B
Python
Raw Normal View History

from abs import absVal
def absMin(x):
"""
>>>absMin([0,5,1,11])
0
>>absMin([3,-10,-2])
-2
"""
2018-11-11 17:27:36 +00:00
j = absVal(x[0])
for i in x:
if absVal(i) < j:
j = i
return j
def main():
a = [1,2,-11]
print(absMin(a)) # = 1
if __name__ == '__main__':
main()