Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.6 I created a program that generates random numbers and writes them to a txt file Random.txt. I need you to open the Random.txt

Python 3.6

I created a program that generates random numbers and writes them to a txt file "Random.txt". I need you to open the Random.txt file and do selection sort on it (low to high) and the sorted output must be written to a new txt file called "Selection.txt". Also, I need to how much time it took for selection sort to work. So, using the Python time module measure the elapsed time required to do the sorting. So, please do the following: start a timer, sort random numbers using selection sort, stop time, and note the elaspsed time. Provide indented source code and screenshot of output "Selection.txt" to recieve full credit. Thanks. Below is the follwing source code (needs correcting):

import time import random randfile = open("Random.txt", "w") start = int(input('Enter lower limit of random numbers: ')) end = int(input('Enter upper limit of random numbers: ')) for i in range(int(input('How many to generate?: '))): line = str(random.randint(start, end)) randfile.write(line + ' ') print(line) randfile.close() # example of selection sort algorithm : needs modification def swap(a, i, j): (a[i], a[j]) = (a[j], a[i]) def selectionSort(a): n = len(a) for startIndex in range(n): minIndex = startIndex for i in range(startIndex+1, n): if (a[i] < a[minIndex]): minIndex = i swap(a, startIndex, minIndex) 

.

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago