#求个神,大学题, 打印最大和最小的数字,如果用户输入的不是有效数字, 用try/except ,

英文题目:
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.
中文翻译:
5.2编写程序,反复提示用户输入整数,直到用户输入“done”。一旦输入“完成”,打印出最大和最小的数字。如果用户输入的不是有效的数字,则使用try/except捕获该数字,并输出适当的消息,忽略该数字。输入7、2、bob、10和4并匹配下面的输出。

5.2

def main():
    arr = []
    while True:
        num = input('Input a number:')
        if num == 'done':
            break
        else:
            try:
                arr.append(int(num))
            except ValueError:
                print('Invalid input')
    print(f'maximum is {max(arr)}')
    print(f'mininum is {min(arr)}')
if __name__ == '__main__':
    main()

result:

Input a number:7
Input a number:2
Input a number:bob
Invalid input
Input a number:10
Input a number:4
Input a number:done
maximum is 10
mininum is 2

最后的结果要求是
Invalid input
maximum is 10
minimum is 2