Python 9/9 help needed


#1

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=float(average(student["homework"]))
quizzes=float(average(student["quizzes"]))
tests=float(average(student["tests"]))
return float(0.10*homework+0.30*quizzes+0.60*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"

class_list = [lloyd,alice,tyler]

def get_class_average(class_list):
results=[]
for name in class_list:
results.append(get_average(name))
return average(results)

class_average=get_class_average(class_list)
print class_average

letter_grade=get_letter_grade(get_class_average(class_list))
print letter_grade

the error message said "One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade"

Can anyone help me with this?


#2

call the class_list , students instead


#3

Thank you so much. It worked!!!


#4

Hey thanks! It works to me as well, but now i got another problem

Oops, try again.
Did you remember to print the average of the class? It looks like "83.8666666667" wasn't printed.

When it's actually printed on the screen...

This is my code:

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(numbers):
    total = sum(numbers)
    total = float(total)/len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return (0.1*homework + 0.3*quizzes + 0.6*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 "Lloyd final grade is: %s" % get_letter_grade(get_average(lloyd))
print "Alice final grade is: %s" % get_letter_grade(get_average(alice))
print "Tyler final grade is: %s" % get_letter_grade(get_average(tyler))

def get_class_average(students):
    results= []
    for item in students:
        results.append(get_average(item))
    return average(results)

print "Class average score: %s" % get_class_average(students)
print "Class average grade : %s" % get_letter_grade(get_class_average(students))

Help please!


#5

Sorry, solved it, i erased the "The class average score, ..." and it works hehe


#6

students = [lloyd, alice, tyler]
print get_class_average(students)
print get_letter_grade(get_class_average(students))


#7

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]

Add your function below!

def average(numbers):
total = sum(numbers)
total = float(total) / len(numbers)
return total

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
the_average = (homework*.10) + (quizzes*.30) + (tests *.60)
return the_average

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"
else:
return "F"

def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)

print get_class_average(students)
print get_letter_grade(get_class_average(students))

def each_student(student):
for student in students:
print(student["name"], "average")
print(get_letter_grade(get_average(student)), get_average(student))

each_student(students)

print get_letter_grade(get_average(lloyd))

print("\nClass average")
print(get_letter_grade(get_class_average(students)), get_class_average(students))