python —Code that prints the average, maximum, and minimum values of the number of n entered.

Asked 1 years ago, Updated 1 years ago, 288 views

I want to write a code for the average, maximum, and minimum values of the numbers I got from the input person, 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)

python

2022-12-18 07:01

1 Answers

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)


2022-12-18 11:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.