Once again, I will allow you the OPTION of working with a partner today. I STRONGLY encourage you to use a partner, but I will not require this option. If you work with a partner you should be working on one computer and following the rules of paired programming. Overall, I think it will be better for you to work with a partner, but it is up to you.
I recommend you read the entire lab before you begin working on the assignment. Make sure you understand the general assignment before you begin. Ask questions EARLY. Don't wait 90 minutes into the lab to ask us a question about just getting started.
LOOK at the the following function code. It defines and modifies a list in an attempt to demonstrate a number of pieces of functionality of a list. Notice that this code contains 10, numbered print statements.
[Q1] Without writing or running the code, simply read the code and predict what will be printed at each print statement.
Now copy this code in to a python editor and run the function.
[Q2] What is actually printed?
[Q3] For each place that your prediction is incorrect, write an explanation of what you thought was going to happen and what actually happened.
Although Python provides us with many list methods, it is good practice and very instructive to think about how they are implemented.
Before you begin, please create a new Python file called lab10.py and write the traditional comments at the top (file, author(s), and description).
Now, for each of the following list methods, write the corresponding function in your lab10.py file that should work similarly.
Python list method (Don't use any of these when writing your functions!)
|Your function (this is the function you need to write)||What it does|
|myList.count(item)||myCount(myList,item)||Returns an integer representing how many times the given item is in the given list. Could be from zero up to infinity.|
|myList.index(item)||myIndex(myList,item)||Returns an integer representing the index of the first occurrence of the given item in the given list. Returns from zero up to inifinity if the item is found. Returns -1 if it is not in the list.|
|item in mylist||contains(myList,item)||Returns True if the item is present in the list and False if it is not.|
|myList.insert(index,item)||myInsert(myList,index,item)||Returns a new list consisting of everything from the old list but with the new item inserted at the given index. If index is not valid (less than zero), then the function returns the original list with no changes.|
|myList.reverse()||myReverse(myList)||Returns a new list consisting of the original list completely backwords.|
I've written a testing suite to test your code. Please right-click on this link and download this file into the same directory as your lab10.py file: tester.py.
Take a look at how this tester works. Run the tester (click Run or press F5).
[SIG 1]: Once you've fixed all the errors uncovered in the tester, raise your hand for a signature.
This week I will again ask you to submit your code using the eLearning submission system.
Follow the directions on the system to select the appropriate course and assignment and submit
Don't forget to hand in your answer sheet to the professor or TA before you leave!