Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve in Python (ASAP, within the next 30 min) , please. PLEASE READ THE INSTRUCTIONS CAREFULLY. THE NUMBERS NEED TO BE SORTED IN DESCENDING ORDER

Solve in Python (ASAP, within the next 30 min), please.

PLEASE READ THE INSTRUCTIONS CAREFULLY. THE NUMBERS NEED TO BE SORTED IN DESCENDING ORDER. 3RD TIME POSTING THE QUESTIONS AS THE FIRST @ ANSWERS WERE WRONG.

In the code below, the selection-sort function repeatedly finds the smallest number in the current list and swaps it with the first one. Rewrite this program by finding the largest number and swapping it with the last one. Write a test program that reads in numbers entered in one line, invokes the function, and displays the sorted numbers.

THE CODE IS COPIED BELOW BUT PLEASE POST ONE WITH THE INDENTATIONS AND A TEST RUN. THANK YOU!

image text in transcribed

def selectionSort(lst):

for i in range(len(lst) - 1):

# Find the minimum in the lst[i : len(lst)]

currentMin = min(lst[i : ])

currentMinIndex = i + lst[i: ].index(currentMin)

# Swap lst[i] with lst[currentMinIndex] if necessary

if currentMinIndex != i:

lst[currentMinIndex], lst[i] = lst[i], currentMin

def main():

lst = [-2, 4.5, 5, 1, 2, -3.3]

selectionSort(lst)

print(lst)

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

What do you mean by dual mode operation?

Answered: 1 week ago

Question

Explain the difference between `==` and `===` in JavaScript.

Answered: 1 week ago