Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python 3+ Given the following list: myList = [1, 10, 20, 21, 5, 7, 9, 13,

ID: 3734878 • Letter: U

Question

Using Python 3+ Given the following list:

myList = [1, 10, 20, 21, 5, 7, 9, 13, 10, 20, 55]

Create one program.  As you change values in the list do not keep going back to the original list, but keep doing the problems based on the new list you just created. I expect the myList to equal [1, 5, 7, 8, 9, 12, 13, 15, 15, 16, 20, 20, 21] when you are done. Make sure that you are printing out the list values for each operation so I can see the result of what you did. Put in comments, so I can see each of the following steps you are doing.

Find the length of the list.

Find the sum of all the numbers in the list. print that sum.

Find the largest number and the index of the largest number. Print the largest number and the index

Test in a loop to see if each value in the list is equal to 21. Use an "if" statement. Tell me the index where you find the 21.

Change all 10's in the list to 15, then print the list.

Create a new list [20, 8] and then concatenate the two lists together (old first then new second), and finally print the new concatenated list, but call it the same name as the original list (myList).Print the list.

With the append( ) method add a 12 to the end of the list, then print the list.

With the insert( ) method, add a 16 to the front of the list, then print the list.

Sort the list, then print the list.

With the pop( ) function, delete the last item in the list, then print the item that was deleted from the list, as well as the list.

Count how many 20's are in the list. Print the count.

With remove(), delete the first number 20 from the list, then print the list.

Explanation / Answer

myList = [1, 10, 20, 21, 5, 7, 9, 13, 10, 20, 55] print("Length of list : %d" %len(myList)) print("Sum of list : %d" %sum(myList)) largest = myList[0] largestIndex = 0 for i in range(1, len(myList)): if myList[i] > largest: largestIndex = i largest = myList[i] print("Largest value is : ", largest, " and its index is : ",largestIndex) searchIndex = -1 for i in range(len(myList)): if myList[i] == 21: searchIndex = i if searchIndex != -1: print("You can find 21 at ", searchIndex, " index in the list") for i in range(len(myList)): if myList[i] == 10: myList[i] = 15 print(myList) newList = [20, 8] myList = myList + newList print(myList) myList.append(12) print(myList) myList.insert(0,16) print(myList) myList.sort() print(myList) last = myList.pop() print("The item deleted from list ", last) print(myList) print("Number of 20's in the list : ", myList.count(20)) for i in range(len(myList)): if myList[i] == 20: myList = myList[:i] + myList[i+1:] break print(myList)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote