samedi 19 avril 2014

python - calcul des moyennes et déterminer le plus bas et des valeurs plus élevées - Stack Overflow


I have split up a list with names and corresponding scores and have stored them in a dictionary called students. But with these scores, I have been asked to figure out the average score, minimum score and maximum score. I am a beginner and a student so a step by step explanation would be greatly appreciated.


def getStatistics(students):

# Initialize properly the values of the average score, minimum score, and maximum score.
average = 0
lowest = True
highest = True
scoreTotal = 0

The reason why the variables above were labeled that way is because in my main function, which calls on this function, had a built in call with those names. But whenever I go to run the program, it doesn't print any of it.


#  loop through the dictionary, and
# calculate the average score, the highest score and the lowest score
# of the students in the dictionary.

i = 0
for grade in students:
scoreTotal += grade[i]
i = i + 1
average = scoreTotal/i
lowest = min(grade[i])
highest = max(grade[i])

# The function must return back the average, highest and lowest score.
return average, highest, lowest

In the main function it had this: (the "nameToMarksMap" is the function from the previous part with the dictionary students)


 average, highest, lowest = getStatistics(nameToMarksMap)

print "Average:", average, "Highest:", highest, "Lowest:", lowest

Nothing is being printed, can anyone explain why? I keep getting errors.




finish the function with


def getStatistics(students)
...
# snip
...
return average, highest, lowest


I have split up a list with names and corresponding scores and have stored them in a dictionary called students. But with these scores, I have been asked to figure out the average score, minimum score and maximum score. I am a beginner and a student so a step by step explanation would be greatly appreciated.


def getStatistics(students):

# Initialize properly the values of the average score, minimum score, and maximum score.
average = 0
lowest = True
highest = True
scoreTotal = 0

The reason why the variables above were labeled that way is because in my main function, which calls on this function, had a built in call with those names. But whenever I go to run the program, it doesn't print any of it.


#  loop through the dictionary, and
# calculate the average score, the highest score and the lowest score
# of the students in the dictionary.

i = 0
for grade in students:
scoreTotal += grade[i]
i = i + 1
average = scoreTotal/i
lowest = min(grade[i])
highest = max(grade[i])

# The function must return back the average, highest and lowest score.
return average, highest, lowest

In the main function it had this: (the "nameToMarksMap" is the function from the previous part with the dictionary students)


 average, highest, lowest = getStatistics(nameToMarksMap)

print "Average:", average, "Highest:", highest, "Lowest:", lowest

Nothing is being printed, can anyone explain why? I keep getting errors.



finish the function with


def getStatistics(students)
...
# snip
...
return average, highest, lowest

0 commentaires:

Enregistrer un commentaire