Part 9 writes the next error "Oops, try again. One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade" plz help, thanks from ahead


#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)
    total = total / len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return (homework * 0.1) + (quizzes * 0.3) + (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(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)
    
print get_class_average([lloyd, alice, tyler])
print get_letter_grade(get_class_average([lloyd, alice, tyler]))


#2

Hi, @rkgames ,

In Exercise 3: Put It Together, you had to write this assignment statement ...

students = [lloyd, alice, tyler]

Regardless of whether or not you wrote it then, it is now missing.

After you restore that statement, you can use the students variable in the final two statements, as follows ...

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

#3

I did not write the statement

students = [lloyd, alice, tyler]

As written below, my program returned the expected results. Is this a in the tutorial, or am I missing something. My code reads almost identically to OP, but I got errors regarding number of arguments when I tried to get_glass_average(lloyd, alice, tyler)

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]
}

def average(numbers):
#averages a list of numbers
total = sum(numbers) # adds the numbers in the list together
total = float(total) #converts the total to a float
average = total / len(numbers) #divides by the length of the list
return average

def get_average(student):
#Gives a weighted score based on homework, quizzes, and tests
#Entering the student's name first averages the scores using average(numbers)
#Then it weights those scores

homework = average(student["homework"]) # Runs the averaging fuction on "homework" 
quizzes = average(student["quizzes"]) #Averages quizzes
tests = average(student["tests"]) # Averages tests

#return a total score based on weighted averages
return (homework * .10) + (quizzes * .30) + (tests * .60)

def get_letter_grade(score):
#Assigns a letter grade to a 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(students): #Calculates the class average
results = [] # initializes an empty results list
for student in students: # for each student in the list of students
average_grade = get_average(student) #average their grade
results.append(average_grade) # add their grade to the results list
return average(results) #average the results list, giving class average

print get_class_average(students) #returns a numerical class average
print get_letter_grade(get_class_average(students)) # return class average letter grade


#5

@cssplayer71222 ,

The get_class_average function header is as follows ...

def get_class_average(students):

Since it has one parameter, you must pass it one argument when you call it. For it to execute properly, the argument should be a list of student dictionaries.

This call contains three arguments instead of one, so it raises an error ...

get_glass_average(lloyd, alice, tyler)

Instead, add this statement to your program ...

students = [lloyd, alice, tyler]

... then you can reliably do this, even if the page has been refreshed to clear memory of variables from previous exercises ...

print get_class_average(students)

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.