Cody Bable

Generation

generate functionTue, 23 May 2023

create a function of a set of integers and a value for which you need to find the nearest one.

def near(list, i): for x in list: if abs(i - x) < abs(i - y): y = x return y near([1,2,3,4,5], 4.2)

Questions about programming?Chat with your personal AI assistant