Question

In: Computer Science

11. Print the length of the new list out to the screen. Ensure the new list...

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

Solutions

Expert Solution

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


Related Solutions

1. Find and print the length of the list listTest. 2. We can test if an...
1. Find and print the length of the list listTest. 2. We can test if an item exists in a list or not, using the keyword in It will give you a boolean response if a certain element is present. Find whether 'p' or 'P' is present in listTest, and print the results. Print results first for 'p' and then for 'P' as shown in example below. For example: Test Result listTest=['c','i','s','c','1','0','6','P','y','t','h','o','n'] False True 3. We can delete one or...
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
"PYTHON" Declare a list that is initialized with six of your favorite sports teams. Print out...
"PYTHON" Declare a list that is initialized with six of your favorite sports teams. Print out the number of teams to the shell. Use a for loop to print out the teams to the shell. 2. a. Declare a sporting goods list, initially with no elements. b. Use a while loop to prompt the user for a sporting goods item and append the item to the list. c. Break out of the loop when the user enters exit; do NOT...
What will the following code segments print on the screen? int num = 3; switch (num){...
What will the following code segments print on the screen? int num = 3; switch (num){             case 1:                         System.out.println(“Spring”); case 2:                         System.out.println(“Summer”); case 3:                         System.out.println(“Autumn”); case 4:                         System.out.println(“Winter”); }
The amount of time Americans spend in front of a screen has a mean of 11...
The amount of time Americans spend in front of a screen has a mean of 11 hours with a standard deviation of 2.7 hours. What is the probability that a random chosen American spends more than 12 hours in front of a screen? Represent the probability with a graph.
Write a complete Java program to print out the name bob
Write a complete Java program to print out the name bob
Question 11 mystring.length() or mystring.size() will return the length of the string in mystring. Question 11...
Question 11 mystring.length() or mystring.size() will return the length of the string in mystring. Question 11 options: True False Question 12 To access an element of an array of structures you use the ________ operator. Question 12 options: Dot Bitwise Logical Comparison Question 13 Question 13 options: What would be printed from the following C++ program? #include #include using namespace std; struct Point { int x; int y; }; void makeTriangle(Point p[]); int main() { Point p[3]; int i; makeTriangle(p);...
List and explain the system activites that are required to be logged to ensure compliance with...
List and explain the system activites that are required to be logged to ensure compliance with the Sarbanes Oxley Act of 2002. this is for an Information Systems Security class required for Accounting major
The following code was meant to print out the elements in an array in reverse order....
The following code was meant to print out the elements in an array in reverse order. However, it does not behave correctly. public static void reverse(int[] a, int index) {       if (index == (a.length - 1))         System.out.printf("%d%n", a[index]);       else {         reverse(a, index); What does it do? Explain why it behaves in this way and There is more than one error in the code. Correct the code so that it will recursively print out the elements of...
C++ In this lab you will be using nested for loops to print out stars in...
C++ In this lab you will be using nested for loops to print out stars in a Diamond pattern such as this: * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** *** * For example , if number of rows=8 then the above pattern is derived. You are to take the input for the number of lines(rows) from a file named "input_diamond" and output the pattern into both the terminal and an output file named "output_diamond".
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT