Daily Python 7 – Writing our own max()

Implement a function that takes as input three variables, and returns the largest of the three. Do this <b>without</b> using the Python max() function!

The goal of this exercise is to think about some internals that Python normally takes care of for us. All you need is some variables and if statements!

e.g max_number(1,2,3) >>> 3

def max_number(n1, n2, n3):
    current_max = n1
    if current_max > n2 and current_max > n3:
        return current_max
    elif current_max < n2:
        current_max = n2
    if current_max > n3:
        return current_max
    else:
        return n3