How to find the maximum and minimum from the list by using loops
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
Comments
Leave a comment