
2.15 LAB: Descending selection sort with output during execution
Write a program that takes an integer list as input and sorts the list into descending order using selection sort. The program should use nested loops and output the list after each iteration of the outer loop, thus outputting the list N-1 times (where N is the size of the list).
Important Coding Guidelines:
- Use comments, and whitespaces around operators and assignments.
- Use line breaks and indent your code.
- Use naming conventions for variables, functions, methods, and more. This makes it easier to understand the code.
- Write simple code and do not over complicate the logic. Code exhibits simplicity when it’s well organized, logically minimal, and easily readable.
Ex: If the input is:
20 10 30 40the output is:
[40, 10, 30, 20] [40, 30, 10, 20] [40, 30, 20, 10]Ex: If the input is:
7 8 3the output is:
[8, 7, 3] [8, 7, 3]Note: Use print(numbers) to output the list numbers and achieve the format shown in the example.
numbers = []
user_input = input()
tokens = user_input.split()
for token in tokens:
numbers.append(int(tokens))
#Convert the string input into an array of integers.
for j in range(len(numbers)-1):
# Find index of smallest remaining element
index_largest = j
for j in range(j+1, len(numbers)):
if numbers[j] < numbers[index_largest]:
index_largest = j
# Swap numbers[i] and numbers[index_smallest]
temp = numbers[j]
numbers[j] = numbers[index_largest]
numbers[index_largest] = temp
print(numbers)
![SCTU Class Homepage.
zy Section 2.15 - CS 233T: Fun X
= zyBooks
✰ learn.zybooks.com/zybook/CS233-2204A-01-2204A/chapter/2/section/15
My library > CS 233T: Fundamentals of Data Structures home >
2.15: LAB: Descending selection sort with output during execution
LAB
ACTIVITY
Note: Use print (numbers) to output the list numbers and achieve the format shown in the example.
422794.2543518.qx3zqy7
6
7
1 numbers = []
2 user_input = input()
3 tokens = user_input.split()
4 for token in tokens:
5
8
9
10
11
Section 2.1 - CS 233T: Fund X
12
13
14
15
- 16 17 18
2.15.1: LAB: Descending selection sort with output during execution
Thank you. Your reservation X
numbers.append(int (tokens))
#Convert the string input into an array of integers.
for j in range (len (numbers)-1):
# Find index of smallest remaining element
index_largest = j
for j in range(j+1, len(numbers)):
if numbers [j] < numbers [index_largest]:
index_largest = j
Develop mode
# Swap numbers[i] and numbers [index_smallest]
temp = numbers[j]
numbers [j] = numbers [index_largest]
Submit mode
Enter program input (optional)
20 10 30 40
main.py
Print - Your Confirmed Rese X
b Answered: CHALLENGE AC
zyBooks catalog
0/10
Load default template...
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
second box.
le
+
? Help/FAQ
Stacey Queen
X
:
3:46 PM
8/29/2022](https://content.bartleby.com/qna-images/question/788fc729-a951-45c4-9909-47eea7bbf82f/babe527b-0f0e-4bd2-9ba2-6f78b61554e4/ppcn7pi_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

hi this helps me wiht the solution but how can I make it indented (image for reference)
Thanks
![1:Compare output
Output is nearly correct, but whitespace differs. See highlights below. Special character legend
Input
Your output
Expected output
20 10 30 40
[40,10,30,20] [40,30,10,20] [40,30,20,10]
[40, 10, 30, 2014
[40, 30, 10, 2014
[40, 30, 20, 10]](https://content.bartleby.com/qna-images/question/a090ff11-7282-4dfe-a94b-07141c4dc3b0/867477ae-de7a-41d1-96cb-aec6ffe3856e/99j924a_thumbnail.png)
hi this helps me wiht the solution but how can I make it indented (image for reference)
Thanks
![1:Compare output
Output is nearly correct, but whitespace differs. See highlights below. Special character legend
Input
Your output
Expected output
20 10 30 40
[40,10,30,20] [40,30,10,20] [40,30,20,10]
[40, 10, 30, 2014
[40, 30, 10, 2014
[40, 30, 20, 10]](https://content.bartleby.com/qna-images/question/a090ff11-7282-4dfe-a94b-07141c4dc3b0/867477ae-de7a-41d1-96cb-aec6ffe3856e/99j924a_thumbnail.png)
- The chapter is nested lists Create code in python using for loops Thanks!arrow_forwardPlease help me, create your won code Create a function that takes a 2D list and an integer v, and returns the number of times the value v is in the list of lists. Add the Nsteps variable to count how many times the loops execute and display a message.• The main program must give a 2D list (no need to generate it, just create it manually), call the function, and display the result example it's the picturearrow_forwardRecall the following segment of Java code for computing the set-difference of two given arrays (note that the lines have been numbered for the sake of reference): (1) int[] a, b; (2) (3) (4) (5) (6) (7) (8) (9) (10) count=0; (11) for (int i=0; i<=a.length-1; i++) { (12) (13) (14) (15) (16) (17) (18) (19) (20) (21) (22) (23) } (24) (25) int[] ans = new int[count]; (26) for (int i=0; i<-count-1; count++) (27) // Input the arrays a and b here int[] tempAns; int count,j; boolean found; tempAns = new int[a.length]; found = false; j-e; while (j<-b.length-1 && !found) { if (a[i]==b[j]) found = true; j+; } if (!found) { tempAns[count]=a[i]; count++; } ans[i] = tempAns[i]; Suppose we want to modify the above code to compute the set union of the arrays a and b, i.e., the set of all elements that are in either a or b. Which of the following changes would accomplish that?arrow_forward
- C) Create a program that generates an eight-digit account number. The program should generate eight random numbers, each in the range of 0 to 9, and assign each number to a list element. Then write another loop that displays the entire contents of the list without the []. PYTHONarrow_forwardPython programming only NEED HELP PLEASEarrow_forwardLottery number generator: Write a program that generates aseven-digit lottery number. The program should have a loopto generate seven random numbers, each in the range 0through 9 and assign each number to a list element.2. Write another loop to display the contents of the list.3. Tip: You will need to create/initialize your list before you canassign numbers to it.4. Use program 7-1 sales_list as an example. You will start witha seven-digit lottery number that contains all zeros. Then inyour loop, you will assign a random number instead ofgetting the data from the user.Turn in your program to the practice assignment link in coursecontent.arrow_forward
- Assume that the variable data refers to the list [5, 3, 7]. Write the expressions that perform the following tasks: a. Replace the value at position o in data with that value's negation. b. Add the value 10 to the end of data. c. Insert the value 22 at position 2 in data. d. Remove the value at position 1 in data. e. Add the values in the list newData to the end of data. f. Locate the index of the value 7 in data, safely. g. Sort the values in data.arrow_forwardpython LAB: Subtracting list elements from max When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that adjusts a list of values by subtracting each value from the maximum value in the list. The input begins with an integer indicating the number of integers that follow.arrow_forward1c) Average sentence length We will create a function ( avg_sentence_len ) to calculate the average sentence length across a piece of text. This function should take text as an input parameter. Within this function: 1. sentences : Use the split() string method to split the input text at every '.'. This will split the text into a list of sentences. Store this in the variable sentences . To keep things simple, we will consider every "." as a sentence separator. (This decision could lead to misleading answers. For example, "Hello Dr. Jacob." is actually a single sentence, but our function will consider this 2 separate sentences). 2. words : Use the split() method to split the input text into a list of separate words, storing this in words . Again, to limit complexity, we will assume that all words are separated by a single space (" "). (So, while "I am going.to see you later" actually has 7 words, since there is no space after the ".", so we will assume the this to contain 6 separate…arrow_forward
- To determine if two lists of integers are equivalent, you must write a function that accepts the lists as input and returns true or false (i.e. contain the same values). The greatest value of each list must be shown if the lists are dissimilar and the procedure is effective.arrow_forwardInteger num_reading is read from input, representing the number of integers to be read next. Read the remaining integers from input and insert each integer at the front of reading_list at position 0.arrow_forwardLargest Value. Create a program that uses a list to store input values, and outputs the largest value entered at its location in the list. The program shall accept input values until the user enters -1. And Next Movie Time. Create a program that shows the user when the next showing for a movie is. The program first reads the different showing times (only hours) in a 24-hour clock format (that is, 1PM is 13, 6PM is 18, etc.). The program then asks when a customer wants to go to the movies. The program replies with the time for the next showing. If the next showing matches the hour input by the customer, show the next showing after that. If the next showing is past the last one, the program shall output, “There are no more showings.”, Here is a sample execution: I am trying to use these programs as practice for practicing lists, strings and inputs. But am struggling a bit after laying down the foundation on each problem. I plan to put them into thonny to compare them with my own work.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





