Maximum of three integers

  1. Analyse which of these functions compute correctly the maximum of three integers. You can use the three following sets of values for parameters (a, b, c): (1, 2, 3), (2, 3, 1) and (3, 1, 2).

    def func1(a, b, c):
        maxim = a
        if b > maxim:
            maxim = b
        elif c > maxim:
            maxim = c
        return maxim
    

    def func2(a, b, c):
        maxim = a
        if b > maxim:
            maxim = b
        if c > maxim:
            maxim = c
        return maxim
    

    def func3(a, b, c):
        maxim = a
        if b > maxim:
            maxim = b
        else:
            maxim = c
        return maxim
    
  2. Write the function maximum_of_3 that takes three integer values as input and returns the maximum without using the max function of Python. Use the previous correct code and devise other alternative codes.

    Save the function in the file maxim3.py. The function must pass the following doctest:

    >>> maximum_of_3(1,2,3)
    3
    >>> maximum_of_3(1,3,2)
    3
    >>> maximum_of_3(3,1,2)
    3
    >>> maximum_of_3(5,5,5)
    5
    >>> maximum_of_3(5,5,2)
    5
    
    

    Note

    You can download a file with tests maxim3.txt

    Solution

    You have some solutions in the file maxim3.py