# Allison Obourn # CSC 110, Autumn 2017 # Lecture 28 # This file is an example of what we are looking for when we ask you to # write down your debugging and testing process. It documents what you # try, what result you get and therefore what change you make or try next. # Documnet steps even if they lead to a dead end. We want to see your thinking! 1. Run the program as is. Got this error message: Traceback (most recent call last): File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 19, in main() File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 7, in main remove_bad_pairs(data) File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 14, in remove_bad_pairs while(i < len(lis)): UnboundLocalError: local variable 'i' referenced before assignment Looked at line 14 variable i, noticed it was only defined in if statement, moved definition outside if statement 2. Ran it again. Ran for a long time, eventually I had to halt the program. Looked at the only loop I have and its condition. Notice i was never updated. Added an update for i in the loop. 3. Ran it again Traceback (most recent call last): File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 20, in main() File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 7, in main remove_bad_pairs(data) File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 16, in remove_bad_pairs lis.remove(i - 1) ValueError: list.remove(x): x not in list Looked at line 16. Noticed that I put i += 1 in a place where it ran every time but I don't want it to run if I remove because that means I skip the ones that I remove and will go over the end. Added an else. 4. Ran it again. Traceback (most recent call last): File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 21, in main() File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 7, in main remove_bad_pairs(data) File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 16, in remove_bad_pairs lis.remove(i - 1) ValueError: list.remove(x): x not in list Same error. Noticed that I am removing at i - 1 meaning I need to go down one index when I remove. Added i -= 1 in if 5. Ran it again. Traceback (most recent call last): File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 22, in main() File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 7, in main remove_bad_pairs(data) File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 16, in remove_bad_pairs lis.remove(i - 1) ValueError: list.remove(x): x not in list Added prints for lis and i in the if right before the removes 6. Ran it again [3, 5, 2, 7, 45, 43, 5, 3] 5 Traceback (most recent call last): File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 24, in main() File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 7, in main remove_bad_pairs(data) File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 18, in remove_bad_pairs lis.remove(i - 1) ValueError: list.remove(x): x not in list Calculated that since i is 5 and I want to remove the thing at index 5 my index is fine. Realized though that remove doesn't do this. Remove removes a value not an index. switched remove to pop. 7. Ran again [3, 5, 2, 7, 45, 43, 5, 3] 5 [3, 5, 2, 7, 43, 3] 5 Traceback (most recent call last): File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 24, in main() File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 7, in main remove_bad_pairs(data) File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 19, in remove_bad_pairs lis.pop(i) IndexError: pop index out of range Realized that need to decrease i after popping i - 1 so that pop what was at i 8. Ran again. It ran without errors! Output: [3, 5, 2, 7, 45, 43, 5, 3] 5 [3, 5, 2, 7, 5, 3] 5 [3, 5, 2, 7] The first four lines are from the prints I added. The last is what the program should print. Success with this list. 9. Try with a different list. replace with [3, 3, 3, 3, 3, 3] got [3, 3, 3, 3, 3, 3] which is correct 10. Try an a list with an odd length [3, 5, 2, 7, 45, 43, 5] Got the following error: Traceback (most recent call last): File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 26, in main() File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 8, in main remove_bad_pairs(data) File "C:/Users/allison/Documents/110/17au/bad_pairs.py", line 13, in remove_bad_pairs v.remove(lis[-1]) NameError: name 'v' is not defined Looked at v on line 13. Can't find v anywhere else in file. It is a remove call which, like before should be a pop. pop and remove are list functions and the only list is lis so should be called on lis 11. Ran program again. Got the following [3, 5, 2, 7] which is correct 12. Try running the program with an empty list. Got [] which is correct