Take a list of nums and return max and min Exercise 6: Rewrite the program that prompts the user for a list of numbers and prints out the maximum and minimum of the numbers at the end when the user enters “done”. Write the program to store the numbers the user enters in a list and use the max() and min() functions to compute the maximum and minimum numbers after the loop completes.


num_list = []

num = input('Please enter a number: ')

while num != 'done' and num != 'DONE':
    try:
        num_list.append(int(num))
        num = input('Please enter a number: ')
    except:
        num = input("Not a number. Please enter a number Or 'done' to finish: ")

try:
    print('Maximum number: ', max(num_list))        
    print('Minimum number: ', min(num_list))
except:
    print('NO INPUT!')
Avoid repeating yourself: use a single input call; it isn't much here, but it is easily error-prone if your "initialization" phase is several steps long. The usual idiom in such case is to use a while True loop and test the condition after the initialization to break if necessary.
Please avoid bare except, this is a bad habit to get into. This will catch all exceptions, including the ones you're not expecting (such as KeyboardInterrupt if the user hits Ctrl+C) and, thus, not ready to handle. In both cases, you’re expecting ValueErrors here.
Use functions, this will make your code much more reusable:




def ask_user_number_list():
    num_list = []
    while True:
        num = input('Please enter a number or 'done' to finish: ')
        if num.lower() == 'done':
            break

        try:
            number = int(num)
        except ValueError:
            print('Invalid input')
        else:
            num_list.append(number)

    return num_list


def search_min_and_max(lst):
    try:
        return min(lst), max(lst)
    except ValueError:
        return None


if __name__ == '__main__':
    bounds = search_min_and_max(ask_user_number_list())
    if bounds is None:
        print('NO INPUT!')
    else:
        print('Maximum number: ', bounds[-1])
        print('Minimum number: ', bounds[0])