Answered step by step
Verified Expert Solution
Question
1 Approved Answer
from random import randint # creating a random number to store number of numbers number _ of _ numbers = randint ( 5 0 ,
from random import randint
# creating a random number to store number of numbers
numberofnumbers randint
# a writing to a file
with opennumbersfile.txtw as file: # opening file
for i in rangenumberofnumbers:
# generating a random number in range
randomnumber randint
# inserting it into the file
file.writestrrandomnumber
# b read the numbers from the file into a list
# list to store the numbers
listofnumbers
with opennumbersfile.txtr as file: # opening file
lines file.readlines
for number in lines:
listofnumbers.appendintnumber
# c sort and show the list
printList of numbers before sorting:
printlistofnumbers
length lenlistofnumbers
# traverse through all elements
for i in rangelength:
# last i elements are already sorted
for j in range length i :
# traverse the array from to length i
# swap if element is greater than next element
if listofnumbersj listofnumbersj :
listofnumbersj listofnumbersj listofnumbersj listofnumbersj
printList of numbers after sorting:
printlistofnumbers
# d calculating the median
if length :
median listofnumberslength
else:
median listofnumberslength listofnumberslength
printThe median of the numbers is: median
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