I'd like to write a code for the average, maximum, and minimum values of the numbers I got from the input, but it doesn't work.
How should I correct it?
At this stage, we only write the code for the maximum value as a test.I don't think it's the right place to write the code for the maximum value.Where should I write it?
def listofname():
members,scores={'name':[]}, {'Score':[]}
while1:
Students = input ("Enter a name or enter 'done' when finished")
ifStudents=='done':break
members ['name'] + = Students
Score=input('Enter score')
scores ['Score'] + = [int(Score)]
if__name__=='__main__':
listofname()
maxOfValue=scores[0]
for i in range (1,len()):
if (maxOfValue<scores[i]):
maxOfValue=scores[i]
print("max number:",scores)
The maximum and minimum values are max()
, min()
functions, and the average value is statistics Mathematical Statistics function module mean()
.
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()
maxScore=max(scores['score'])
print("max number:", maxScore)
© 2025 OneMinuteCode. All rights reserved.