How to compare a variable value to an array
问题 In Python, How can I compare two float variable values to ensure if they are within a certain tolerance of each other? For example: variable = 17.40 array = [14.40, 14.12, 45.50] I need to compare the variable value with the array elements to see which one are close enough. 回答1: From this question that you also asked. Here's a piece of code that will check if your variable is in the array(unless that's not what you meant by compare the variable value with the array elements): TOLERANCE=10**-6