Created
July 16, 2013 21:46
-
-
Save robrocker7/6015440 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
students = [{ | |
"name": "Lloyd", | |
"homework": [90.0, 97.0, 75.0, 92.0], | |
"quizzes": [88.0, 40.0, 94.0], | |
"tests": [75.0, 90.0] | |
},{ | |
"name": "Alice", | |
"homework": [100.0, 92.0, 98.0, 100.0], | |
"quizzes": [82.0, 83.0, 91.0], | |
"tests": [89.0, 97.0] | |
},{ | |
"name": "Tyler", | |
"homework": [0.0, 87.0, 75.0, 22.0], | |
"quizzes": [0.0, 75.0, 78.0], | |
"tests": [100.0, 100.0] | |
}] | |
# def get_letter_grade(score): | |
# if score >= 90: | |
# return "A" | |
# elif score >= 80 and score <90: | |
# return "B" | |
# elif score >= 70 and score <80: | |
# return "C" | |
# elif score >= 60 and score < 70: | |
# return "D" | |
# elif score < 60: | |
# return "F" | |
# else: | |
# return "poop" | |
def average(scores): | |
divide = len(scores) | |
total = 0.0 | |
for score in scores: | |
total += score | |
average = total / float(divide) # added float for more accurate divison | |
return average | |
def get_average(student): | |
return (average(student['homework']) * .1) + \ | |
(average(student['tests']) * .3) + \ | |
(average(student['quizzes']) *.6) | |
def get_class_average(students): | |
average_grade = 0 | |
for student in students: | |
average_grade += get_average(student) | |
return average_grade | |
print get_class_average(students) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment