def findMaxAndMin(L):
if L == []:
return (None,None)
else:
my_min = L[0]
my_max = L[0]
for i in L:
if my_min > i:
my_min = i
if my_max < i:
my_max = i
return (my_max,my_min)
import random
l = list(range(0,10))
random.shuffle(l)
print(l)
##[5, 2, 4, 7, 8, 3, 0, 1, 9, 6]
print(findMaxAndMin(l))
##(9, 0)
l = []
print(findMaxAndMin(l))
##(None, None)
网友评论