Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started