Jul-17-2017, 02:15 PM
Hello all,
Sorry to bother you with yet another noob mystery but again, I find myself stumped. And I'd like to start by saying that I spent a solid hour or more trying to resolve this myself before coming before you to beg for your assistance, again.
Quick recap, I am using a coding for beginners book as the first step in teaching myself Python, I have had fairly good results and even feel bolstered by the fact that when I submitted my previous cry for help I didn't even really know what I was looking for. I now know the idea of what I'm looking for and even have some clue where in my code the problem lies, (I think
) I just still don't have the chops to figure out exactly what I'm missing. I have checked and double checked the code I've created vs. the example in my book and am confident in saying that it matches the example exactly. Here is the code:
I see where the "copy_sort" is defined and I see where it is called back again near the bottom, I've gone through the algorithm and traced it out in my head, and I think I understand it, however I am not getting the same output as the example in my book and I can't figure out why.
Here is my output:
I appreciate any input you can offer.
Best regards,
Sorry to bother you with yet another noob mystery but again, I find myself stumped. And I'd like to start by saying that I spent a solid hour or more trying to resolve this myself before coming before you to beg for your assistance, again.
Quick recap, I am using a coding for beginners book as the first step in teaching myself Python, I have had fairly good results and even feel bolstered by the fact that when I submitted my previous cry for help I didn't even really know what I was looking for. I now know the idea of what I'm looking for and even have some clue where in my code the problem lies, (I think

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
def copy_sort(array): copy = array[:] sorted_copy = [ ] #Algorithm sequence to be added here return sorted_copy while len ( copy ) > 0 : minimum = 0 for element in range ( 0 , len (copy)): if copy[ element ] < copy[ minimum ] : minimum = element print ( '\tRemoving value' , copy[ minimum ],\ 'from' , copy ) sorted_copy.append( copy.pop(minimum)) array = [ 5 , 3 , 1 , 2 , 6 , 4 ] print ( 'Copy Sort...\nArray :' , array ) print ( 'Copy :' , copy_sort( array )) print ( 'Array :' , array ) |
Here is my output:
Output:Copy Sort...
Array : [5, 3, 1, 2, 6, 4]
Copy : []
Array : [5, 3, 1, 2, 6, 4]
>>>
The example in my book looks like this:Output:Copy Sort...
Array : [5, 3, 1, 2, 6, 4]
Removing value 1 from [5, 3, 1, 2, 6, 4]
Removing value 2 from [5, 3, 2, 6, 4]
Removing value 3 from [5, 3, 6, 4]
Removing value 4 from [5, 6, 4]
Removing value 5 from [5, 6]
Removing value 6 from [6]
Copy : [1, 2, 3, 4, 5, 6]
Array : [5, 3, 1, 2, 6, 4]
>>>
Do I have my indent[s] wrong? or did the code not properly define the algorithm?I appreciate any input you can offer.
Best regards,
Quote:If you can't learn to do something well?... Learn to enjoy doing it poorly.