Cody Bable

Generation

generate functionTue, 23 May 2023

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

def closest_number(nums, target): nums.sort() for num in nums: if num >= target: return num return nums[0]

Questions about programming?Chat with your personal AI assistant