Use the list functions learned in class to perform a series of operations and display the output using the following list – [5, 15, 84, 3, 14, 2, 8, 10, 14, 25]. Specifications are as follows:
(a) Print a count of the number of times 14 is in the list. (worth 2 pts)
(b) Print the maximum number in the list. (worth 2 pts)
(c) Print the minimum number in the list. (worth 2 pts)
(d) Print the numbers in the list in reverse order. (worth 2 pts)
(e) Sort the list and print the sorted list. (worth 2 pts)
(f) Print one number randomly chosen from the list. (worth 2 pts)
(g) Randomly shuffle the list and print the output. (worth 2 pts)
(h) Make a deepcopy of the list, change one number in the copied list, then print the original list and the copied list. (worth 6 pts)
Note: You must use list functions to complete all items above.
Your output should look like this:
(a) Count of the number 14 - 2
(b) Maximum number – 84
(c) Minimum number – 2
(d) Reverse list – [25, 14, 10, 8, 2, 14, 3l, 84, 15, 5]
(e) Sorted list – [2, 3, 5, 8, 10, 14, 14, 15, 25, 84]
(f) Random number – 10 (note: could be any number in the list, not necessarily 10)
(g) Shuffled list – [14, 10, 2, 14, 25, 31, 5, 15, 84, 8] (note: your shuffled list may be different)
(h) Original list – [5, 15, 84, 3, 14, 2, 8, 10, 14, 25] Copied list – [5, 15, 83, 3, 14, 2, 8, 10, 14, 25] (note: this assumes you changed the number 84 to 83 in the copied list)
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! =========================================================================== numbers=[5, 15, 84, 3, 14, 2, 8, 10, 14, 25] #a print('Count of the number 14 -{}'.format(numbers.count(14))) #b print('Maximum number - {}'.format(max(numbers))) #c print('Minimum number - {}'.format(min(numbers))) #d numbers.reverse() print('Reverse list - {}'.format(numbers)) #e numbers.sort() print('Sorted list - {}'.format(numbers)) #f import random print('Random number - {}'.format(random.choice(numbers))) #g random.shuffle(numbers) print('Shuffled list - {}'.format(numbers)) #h numbers=[5, 15, 84, 3, 14, 2, 8, 10, 14, 25] deep_copy=[n for n in numbers] deep_copy[2]=deep_copy[2]+1 print('Original list - {}'.format(numbers)) print('Copied list - {}'.format(deep_copy))
Get Answers For Free
Most questions answered within 1 hours.