This is my code to gather list of scores of students. The program will remove the min of list before averaging the scores. But, after removing the min and averaging it. The computation still computes together with the removed min. How can I fix that?
def student_scores():
students_scores = []
scores = ''
while scores != 0:
scores = int(input('Enter your scores or 0 to end: '))
if scores != 0:
students_scores.append(scores)
return students_scores
def compute_total(gradelist):
tot = int()
for num in gradelist:
tot += num
return tot
def drop_lowest(scores):
scores.remove(min(scores))
scores2 = []
scores2.extend(scores)
least = tuple(scores2)
return least
def get_mean(lowest,scores):
mean = lowest / len(scores)
return mean
def main():
scores = student_scores()
total = compute_total(scores)
lowest = drop_lowest(scores)
average = get_mean(total,scores)
print('Scores with lowest score is now removed', lowest)
print('The mean is: ', average)
main()
Currently your code first gets a list of scores, finds the sum of all of those scores, makes a list without the lowest score, and then computes the total of all the original grades / the number of original scores.
If you want to find the mean of scores without taking the lowest score change your main to:
scores = student_scores()
lowest = drop_lowest(scores)
total = compute_total(lowest)
average = get_mean(total,lowest)
which will give you the mean of all the scores without the lowest score.
Hope that helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.