Hello, I created the code below but idk why it returns 4 instead of 4.5. Can someone help me please?

import math

def median(numbers):

numbers = sorted(numbers)

if numbers == []:

return []

elif len(numbers) == 1:

return numbers[0]

else:

for num in numbers:

if len(numbers) % 2 != 0:

num = numbers[math.floor(len(numbers) / 2)]

elif len(numbers) % 2 == 0:

rnum = numbers[len(numbers) / 2]

lnum = numbers[(len(numbers) / 2) - 1]

num = (lnum + rnum) / 2

return num