2018-12-04 17:18:32 +00:00
|
|
|
from Maths.abs import absVal
|
2018-11-03 20:08:13 +00:00
|
|
|
def absMin(x):
|
|
|
|
"""
|
2018-12-04 17:18:32 +00:00
|
|
|
# >>>absMin([0,5,1,11])
|
2018-11-03 20:08:13 +00:00
|
|
|
0
|
2018-12-04 17:18:32 +00:00
|
|
|
# >>absMin([3,-10,-2])
|
2018-11-03 20:08:13 +00:00
|
|
|
-2
|
|
|
|
"""
|
2018-12-04 17:18:32 +00:00
|
|
|
j = x[0]
|
2018-11-03 20:08:13 +00:00
|
|
|
for i in x:
|
2018-12-04 17:18:32 +00:00
|
|
|
if absVal(i) < absVal(j):
|
2018-11-03 20:08:13 +00:00
|
|
|
j = i
|
|
|
|
return j
|
|
|
|
|
|
|
|
def main():
|
2018-12-04 17:18:32 +00:00
|
|
|
a = [-3,-1,2,-11]
|
|
|
|
print(absMin(a)) # = -1
|
2018-11-03 20:08:13 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-12-04 17:32:53 +00:00
|
|
|
main()
|