-
-
Save codecademydev/c7edefceeff4b1b93a76 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains 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
lloyd = { | |
"name": "Lloyd", | |
"homework": [90.0, 97.0, 75.0, 92.0], | |
"quizzes": [88.0, 40.0, 94.0], | |
"tests": [75.0, 90.0] | |
} | |
alice = { | |
"name": "Alice", | |
"homework": [100.0, 92.0, 98.0, 100.0], | |
"quizzes": [82.0, 83.0, 91.0], | |
"tests": [89.0, 97.0] | |
} | |
tyler = { | |
"name": "Tyler", | |
"homework": [0.0, 87.0, 75.0, 22.0], | |
"quizzes": [0.0, 75.0, 78.0], | |
"tests": [100.0, 100.0] | |
} | |
# Add your function below! | |
def average(numbers): | |
# this function will take sum of numbers, convert it to a floating format, then take the total and divide it by the amount of numbers, and return the average. | |
total = sum(numbers) | |
total = float(total) | |
average = total/ len(numbers) | |
return average | |
def get_average(student): | |
# takes average of homework scores, then quizzes, then tests. then it calculates and returns the weight of each average. | |
homework = average(student["homework"]) | |
quizzes = average(student["quizzes"]) | |
tests = average(student["tests"]) | |
results = (homework * .1) + (quizzes *.3) + (tests * .6) | |
return results | |
def get_letter_grade(score): | |
#this function will take the get_average function, determine what grade they should receive, then print the resulting letter grade. | |
if score >= 90: | |
return "A" | |
elif score >= 80: | |
return "B" | |
elif score >= 70: | |
return "C" | |
elif score >= 60: | |
return "D" | |
else: | |
return "F" | |
student = [lloyd, alice, tyler] | |
def get_class_average(students): | |
results = [] | |
for student in students: | |
results.append(get_class_average(student)) | |
class_average = average(results) | |
return class_average | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment