python 找出最大最小值

largest = None
smallest = None
arr = []
# save the Integer input into an array
while True:
    num = input('Enter a Interger number:')
    if num == "done" :
        break
    try:
        num1 = int(num)
        arr.append(num1)
    except:
        print("input is invaild")
        continue

#print the maxmium number
for i in arr:
    if largest is None:
        largest = i
    if largest < i:
        largest = i
print("Maximum", largest)

#print the smallest number
for i in arr:
    if smallest is None:
        smallest = i
    if smallest > i:
        smallest = i
print("Minimum", smallest)

你可能感兴趣的:(python 找出最大最小值)