#Sort Assignment
import random
import sys
import os

# this permits entering a comment.  Comments are ignored by the program

##If you enter several lines intended
##to be comments you can then use the editor to put in the leading #'s \
##
##With the IDLE editor Select the lines you want to comment, then use 
##the the "Format" menu choice to "Comment Out Region"  or "Uncomment Region".

##The task was to write a Python program that would sort a
##list of numbers from lowest to highest.  The approach
##I lead you through is shown below

#Create the list, and create an empty list of the same size
original_list = [ 18, 24, 32, 55, 22, 4, 61 ]
sorted_list = [ 0,0,0,0,0,0,0]

#make a copy of the list to work with
wrk_list = list(original_list)
# if you used "wrk_list = original_list" confusing things happen.
# Python makes the two identical, so that changes to one causes
# changes to the other.   This can be confusing. 

#find the the number of items in the list
num_items = len(wrk_list)
print ("wrk_list has ",num_items," items")

#Create index counters to  use with each list
wrk_list_index = 0
sorted_list_index = 0

#Create a variable to hold the maximum value found in each inner loop
max = 0

##This approach uses an outer loop which fills in the sorted_list.
##In each cycle of the outer loop the program uses the inner loop
##to find the next value from wrk_list to put into sorted_list.

#Outer loop, each cycle adds one value to the sorted_list
while (sorted_list_index < num_items):
    #reset the list_index for the inner loop
    wrk_list_index = 0
    #reset the max value to 0
    max = 0

    #inner loop,   finds next maximum value in wrk_list.
    #   previously found maximum values were replace with zero
    while (wrk_list_index < num_items):
        #if the next item is greater than max, set max = to that value
        if (wrk_list[wrk_list_index] > max):
            max = wrk_list[wrk_list_index]
            max_index = wrk_list_index # this is needed later, see use below
        #increase the index for this loop
        wrk_list_index = wrk_list_index + 1
        #when this loop completes, max will contain the largest value
        #found, and max_index will be the index number of that item.
        

    #print ("made it out of inner loop") #used in debugging

    #put the max value found into the next cell of the sorted_list
    sorted_list[sorted_list_index] = max

    # increment the sorted_list_index by 1, for the next cycle of the loop
    sorted_list_index = sorted_list_index+1

    #replace the max value found in list with 0 so that it wont be
    #found again
    wrk_list[max_index] = 0

#show the results of the sort
print("The original list was: ",original_list)
print("the sorted list is    :",sorted_list)

#now that you have done all that, here is the Python sort function
#This function sorts from lowest to highest
wrk_list = list(original_list)
wrk_list.sort()
print("\n the Python sorted list is : ",wrk_list)
#we could now reverse the sequence of the list
#You could write Python statements to do this, but you don't have to
wrk_list.reverse()
print("this is the reversed list : ", wrk_list)


 
            
