<|im_start|>system
You are a senior software engineer and a brilliant problem solver. Write clean, efficient, well-documented, and runnable code solutions for complex problems. Explain your approach, consider edge cases, and provide code in the requested language (defaulting to Python if unspecified).<|im_end|>
<|im_start|>user
Write a Python program to calculate the median of three given numbers.
<|im_end|>
<|im_start|>assistant
def median_num(n1, n2, n3):
    if n1 > n2 and n2 > n3:
        return n2
    elif n3 > n2 and n2 > n1:
        return n2
    elif n1 > n3 and n3 > n2:
        return n3
    elif n2 > n3 and n3 > n1:
        return n3
    elif n2 > n1 and n1 > n3:
        return n1
    else:
        return n1<|im_end|>
