In: Computer Science
11. Print the length of the new list out to the screen. Ensure the new list has a length of 25. 12. Append the integer value 42 to the new list. Print the new list to the screen. 13. Permanently sort the new list. Print the new list to the screen. 14. Remove the integer value 42 from the new list. Print the new list to the screen. 15. Implement a for loop to iterate through the new list. For each list value in the for loop, print the value to the screen after dividing the value by 10 and adding 1. Don’t permanently change the list item value in this process. Note: The math is, as an example, 200/10 + 1 = 21. 16. Print the new list out to the screen one more time to demonstrate the list values did not change during the for loop execution. in python
import random
# creating a list of random number for further assignment.
new_list = [random.randint(0,100) for x in range(25)]
print('Original list:\n', new_list)
#11.
# display the original list
print('\nLength of new list:', len(new_list))
#12.
# append 42 and display list again
new_list.append(42)
print('\nAfter appending 42:\n', new_list)
#13.
# sort the list and display again
new_list = sorted(new_list)
print('\nAfter sorting list:\n', new_list)
#14.
# remove 42 and display list again
new_list.remove(42)
print('\nAfter removing 42:\n', new_list)
#15.
# for each value dispay i / 10 + 1
print('\nEeach value after dividing by 10 and adding 1:')
for i in new_list:
print((i / 10) + 1, end = ', ')
# display the list again
print()
print('\nOriginal list:\n', new_list)
As you have not mentioned anything about the new_list data, so I chose the random library to fill the list with 25 random numbers. And I fill the array and work on that array as the questions asked.
FOR ANY TYPE OF MODIFICATION AND HELP OR EDIT, PLEASE COMMENT.
FOR HELP PLEASE COMMENT.
THANK YOU