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 find_closest(num, arr): distance = 9999999999999 closest = 0 for n in arr: if abs(num - n) < distance: distance = abs(num - n) closest = n return closest find_closest(7, [1, 7, 9])

Want to kickstart your project?Use the new AI Studio to create your code