IDLE.
07128669 76 09423988 88 07765600 94 ...
def scores_list_create(file):
create the empty list scores
for each line in file:
set values for id and score using split()
turn score into an integer
add score to the list scores
return scores
def scores_average(list):
set total to 0
for each score in total:
add the score to total
set average by dividing total by the length of list
return average using round to turn it into an integer
def highest_lowest_scores(list):
return the highest and lowest values in the list using max() & min()
FILENAME = "id_scores.txt" file = open(FILENAME, "r") scores_list = scores_list_create(file) print(scores_list) average = scores_average(scores_list) print(average) highest_lowest_scores(scores_list) highest, lowest = highest_lowest_scores(scores_list) print(highest, lowest)
[76, 88, 94, 98, 40, 70, 47, 68, 93, 49, 69, 91, 75, 95, 52, 91, 71, 47, 56, 66, 71, 90, 61, 58, 90, 96, 67, 83, 77, 90, 51, 64, 61, 53, 74, 89, 99, 42, 86] 73 99 40
pass. for loop that prints every line in the file. print statement. split on
the line to assign values to the variables
id and score. print statement. int(). for loop, print the list. print statement. pass statement from
scores_average. for loop that prints each value in the list. print statement. for loop print total. print statement. round. pass statement from
highest_lowest_scores. max
and min. [76, 88, 94, 98, 40, 70, 47, 68, 93, 49, 69, 91, 75, 95, 52, 91, 71, 47, 56, 66, 71, 90, 61, 58, 90, 96, 67, 83, 77, 90, 51, 64, 61, 53, 74, 89, 99, 42, 86] 73 99 40
cd it116/hw/hw10
./hw10.py
[76, 88, 94, 98, 40, 70, 47, 68, 93, 49, 69, 91, 75, 95, 52, 91, 71, 47, 56, 66, 71, 90, 61, 58, 90, 96, 67, 83, 77, 90, 51, 64, 61, 53, 74, 89, 99, 42, 86] 73 71 99 40
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.