user
Create a function to find the closest number to a given number.

Additional Context:
num = 10, list = [3, 5, 7, 8, 11, 16]

Answer:
assistant
def closest_num(num, list):
    closest = None
    for i in list:
        if closest is None or abs(num - i) < abs(num - closest):
            closest = i
    return closest

closest_num(10, [3, 5, 7, 8, 11, 16]) 
# Output: 8