Answer to Question #307349 in Python for H A

Question #307349

How to find the maximum and minimum from the list by using loops


1
Expert's answer
2022-03-07T12:53:07-0500
def maxi(list1):
    for i, j in enumerate(list1):
        if i < len(list1)-1:
            if j > list1[i+1]:
                maxi = list1[i]
            else:
                maxi = list1[i+1]
    return maxi


maxi([1,3,4,2])
4

def mini(list1):
    for i, j in enumerate(list1):
        if i < len(list1)-1:
            if j < list1[i+1]:
                mini = j
            else:
                mini = list1[i+1]
    return mini


mini([4,3,1,2])
1          

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS