+ 2
Find the nearest number to zero in the list
myList = [1,-2,-5,8,9]
7 Answers
+ 7
Manoj Bhaagam ,
before we can help you, please post your code here. we need to see what the issue is.
thanks!
+ 7
ravilnicki ,
very nice code !!!
+ 3
Hello Manoj Bhaagam
You can use the abs() function to solve this problem.
abs(0-n) gives you the distance between 0 and n.
e.g.
abs(0-8) = 8
abs(0-(-2)) = 2
8 > 2 -> -2 is closer to 0 than 8
+ 3
ravilnicki
Cool. I also didn't know that you can use keys.
+ 2
ravilnicki
Of course, you are absolutely right. lol đ