From d72ebb87ac487db334f00ba2aef52cc648ecd879 Mon Sep 17 00:00:00 2001 From: praisearts <34782930+praisearts@users.noreply.github.com> Date: Thu, 24 Oct 2019 09:34:26 +0100 Subject: [PATCH] create findMinMax.py An algorithm to find the largest and smallest elements of a list --- sorting and basics/findMinMax.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 sorting and basics/findMinMax.py diff --git a/sorting and basics/findMinMax.py b/sorting and basics/findMinMax.py new file mode 100644 index 0000000..56db63d --- /dev/null +++ b/sorting and basics/findMinMax.py @@ -0,0 +1,25 @@ +#MAX ALGORITHM +def findMin(list): + + minVal = list[0] + + for i in range(0, len(list)): + if list[i] < minVal: + minVal = list[i] + return minVal + +#MAX ALGORITHM +def findMax(list): + + maxVal = list[0] + + for i in range(0, len(list)): + if list[i] > maxVal: + maxVal = list[i] + return maxVal + + +#TEST +test_list = [9, 8, 23, 1, 200, 10, 90, 11] +print('The smallest elements is : {}'.format(findMin(test_list))) +print('The largest elements is : {}'.format(findMax(test_list)))