1/9
lloyd = {
"name":"Lloyd",
"homework":[],
"quizzes" :[],
"tests":[]
}
alice = {
"name": "Alice",
"homework":[],
"quizzes":[],
"tests":[]
}
tyler = {
"name":"Tyler",
"homework":[],
"quizzes":[],
"tests":[]
}
2/9
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]
}
3/9
class str(object):
def add(self, other):
return True
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]
}
students = [lloyd, alice, tyler]
4/9
lloyd = {
"name": "Lloyd",
"homework": [90,97,75,92],
"quizzes": [88,40,94],
"tests": [75,90]
}
alice = {
"name": "Alice",
"homework": [100,92,98,100],
"quizzes": [82,83,91],
"tests": [89,97]
}
tyler = {
"name": "Tyler",
"homework": [0,87,75,22],
"quizzes": [0,75,78],
"tests": [100,100]
}
students=[lloyd,alice,tyler]
for student in students:
print student['name']
print student['homework']
print student['quizzes']
print student['tests']
5/9
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):
total = sum(numbers)
total = float(total)
return total / len(numbers)
6/9
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):
total = sum(numbers)
total = float(total)
return total / len(numbers)
def get_average(student):
homework = average(student["homework"]) * 0.10
quizzes = average(student["quizzes"]) * 0.30
tests = average(student["tests"]) * 0.60
return homework + quizzes + tests
def get_letter_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
print "You loser!"
kid = lloyd
print "%s's grade is " % kid["name"] + get_letter_grade(get_average(kid))
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
classroom = [lloyd, alice, tyler]
print "The average for the class was "
print get_class_average(classroom)
7/9
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):
total = sum(numbers)
total = float(total)
return total / len(numbers)
def get_average(student):
homework = average(student["homework"]) * 0.10
quizzes = average(student["quizzes"]) * 0.30
tests = average(student["tests"]) * 0.60
return homework + quizzes + tests
def get_letter_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
print "You loser!"
kid = lloyd
print "%s's grade is " % kid["name"] + get_letter_grade(get_average(kid))
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
classroom = [lloyd, alice, tyler]
print "The average for the class was "
print get_class_average(classroom)
def getLetterGrade(score):
score = round(score)
grades = [(90, 'A'), (80, 'B'), (70, 'C'), (60, 'D'), (0, 'F')]
for i in range(len(grades)):
if score >= grades[i][0]:
return grades[i][1]
8/9
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!
students_name = lloyd
def average (blahhh):
total = sum(blahhh)
ave = float(total)/len(blahhh)
return ave
def get_average(students_name):
score = .1 * average(students_name["homework"]) + .3 * average(students_name["quizzes"]) + .6 * average(students_name["tests"])
return score
def get_letter_grade(score):
if score >= 90:
return "A"
elif 80 <= score < 90:
return "B"
elif 70 <= score < 80:
return "C"
elif 60 <= score < 70:
return "D"
elif score < 60:
return "F"
print get_letter_grade (get_average(students_name))
9/9
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!
students = [lloyd,alice,tyler]
def average(data):
return sum(data) / float(len(data))
def get_average(student):
return average(student["homework"]) * 0.1 + average(student["quizzes"]) * 0.3 + average(student["tests"]) * 0.6
def get_letter_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
def get_class_average(class_list):
sumavg = 0
for student in class_list:
sumavg += get_average(student)
return sumavg / float(len(class_list))
print get_class_average(students)
print get_letter_grade(get_class_average(students))