Write a Python program: * Program will use a text file data_xxxxxxx.txt to write
ID: 3828582 • Letter: W
Question
Write a Python program:
* Program will use a text file data_xxxxxxx.txt to write 15 numbers in the range of 0 to 100 (one number in each line), where xxxxxxx represents your ID number.
* Then the program will read these values into a list named numbers.
* Call a function get_average( ) and pass the list to it. The function will calculate and return the average back.
* Call a function sort_list( ) to sort scores in the list in ascending order - use any popular algorithm such as bubble sort, insertion sort or merge sort.
* Call a function get_max( ) and pass the list to it. The function will find the highest score and return it back.
* Call a function get_min( ) and pass the list to it. The function will find the lowest score and return it back.
(Your program will not use any pre-written Python functions to find average, max and min. You will write logic for the same)
* Append average, maximum and minimum scores in separate lines into the text file data_xxxxxxx.txt with appropriate messages such as "average score is 90"
Explanation / Answer
disfile = open('filename.txt') for line in disfile: list = line.split() id = list[4] if id == 'sequence': name = list[0] Sequence = list[5] elif id == 'disorder': Disorder = list[5] print name, ' ', 'Sequence:',' ', Sequence,' ', 'Disorder:',' ', Disorder disfile = open('filename.txt') for line in disfile: list = line.split() id = list[4] if id == 'sequence': name = list[0] Sequence = list[5] elif id == 'disorder': Disorder = list[5] import sys sys.stdout = open('newfile.txt', 'w') print name, ' ', 'Sequence:',' ', Sequence,' ', 'Disorder:',' ', Disorder
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.