Skip to content

Instantly share code, notes, and snippets.

@justutiz
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justutiz/cc20c4add2373db3384a to your computer and use it in GitHub Desktop.
Save justutiz/cc20c4add2373db3384a to your computer and use it in GitHub Desktop.
Find number closest to 0 (zero)
numbers = [2,5,8,1,5,32,6,8,-0.2,3,6,0.3,-2,-3,-8,-20]
t = []
n = []
for i in numbers:
if i > 0:
t.append(i)
else:
n.append(i)
n = max(n)
t = min(t)
if(abs(t) == abs(n) or abs(t) < abs(n)):
print(t)
else:
print(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment