ezoic

Wednesday, February 22, 2017

max function

The function max() from exercise 1) and the function max_of_three() from exercise 2) will only work for two and three numbers, respectively. But suppose we have a much larger number of numbers, or suppose we cannot tell in advance how many they are? Write a function max_in_list() that takes a list of numbers and returns the largest one.

class Solution:
    def max1(self, l1):
        max2=l1[0]
        for i in range(len(l1)):
            if l1[i]>max2:
                max2=l1[i]
            else:
                max2=max2
        return(max2)


kk=Solution()
if __name__=='__main__':

    print(kk.max1([2,3,1,4,53,6,2,9]))


Results:


No comments:

Post a Comment

looking for a man

 I am a mid aged woman.  I was born in 1980. I do not have any kid. no complicated  dating before . I am looking for a man here for marriage...