I'm working on Python code, and I'm writing code that finds the highest, lowest, and average value of my name, score, and score from the data I get.
I can print the name, score, highest and lowest values, but I can't write the code that gives the average value.I've looked at some websites, but none of them work.I tried the code below using the module, but it doesn't work.Do you have any suggestions?
from statistics import median
from path import isan
from itertools import filterfalse
def ScoreList():
scores={'name':[], 'score':[]}
while True:
name = input("Enter a name or enter 'done' when finished")
if name == 'done' —break
scores ['name'] + = [name]
score=input('Enter score')
scores ['score'] + = [int(score)]
return scores
if__name__=='__main__':
scores=ScoreList()
print(scores)
maxScore=max(scores['score'])
print("max score is:",maxScore)
minScore=min(scores['score'])
print("min score is:",minScore)
midScore=mid(scores['score'])
print ("average score is", midScore)
You can get the average by using in .
Rewrite import median
to import mean
and mid(scores['score')
to mean(scores['score')
.
sample code
from statistics import mean
if__name__=='__main__':
score=[10,20,30]
print(score)
print("max score is:", max(score))
print("min score is:",min(score))
print("average score is", mean(score))
Run Results
[10,20,30]
max score is:30
min score is —10
average score is 20
References
© 2025 OneMinuteCode. All rights reserved.