Solution Exercise 32

Write a program that reads integers from the user and stores them in a list. Your program should continue reading values until the user enters 0. Then it should display all of the values entered by the user (except for the 0) in order from smallest to largest, with one value appearing on each line.

Hint:
Use either the sort method or the sorted function to sort the list.

def main():
    list_of_numbers = []
    #We use this boolean to indicate that we are not done
    done = False
    while not done:
        number = int(input("Enter a number. Exit with 0: "))
        if number != 0:
            list_of_numbers.append(number)
        else:
            done = True
    
    #We can either use the sorted function like this
    sorted_list = sorted(list_of_numbers)
    print(sorted_list)
    #Or by using the sort method in the list
    list_of_numbers.sort()
    print(list_of_numbers)
    
if __name__ == '__main__':
    main()