Stuck at the last bit


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/5?curriculum_id=4f89dab3d788890003000096


The error message that comes up says " 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". This message doesn't come in the previous exercises, where one defines the functions. Only when I am trying to print the class average, I get the error message.


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):
     homeworks = average(student["homework"])
     quiz = average(student["quizzes"])
     test = average(student["tests"])
     
     return 0.1*homeworks+0.3*quiz+0.6*test
     
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 get_letter_grade(get_average(lloyd))
     
def get_class_average(students):
     results =[]
     for each in students:
         results.append(get_average(each))
     return average(results) 
     

students_all = [lloyd, alice, tyler]
print get_class_average(students_all)

print get_letter_grade(get_class_average(students_all))


#2

Hi @kaybav ,

You have this ...

students_all = [lloyd, alice, tyler]
print get_class_average(students_all)

print get_letter_grade(get_class_average(students_all))

As of Exercise 3: Put It Together, you should have a variable named students. Use that name instead of students_all.


#3

Hi @appylpye, thank you for your reply, but I fail to understand as to why/how should a trivial changing of variable name be a solution to the error? We are only changing the name, the underlying logic remains the same.


#4

Hi @kaybav ,

Yes, you are correct that the underlying logic remains the same. The Python interpreter has no objection to the name that you used, and did not issue the error message. However, Codecademy checks whether or not your code conforms to their instructions, and issues a message if it does not.

In Exercise 9: How is Everybody Doing?, Codecademy checks again for the variable, students, that you created in Exercise 3: Put It Together, and checks for other variables, as well. If any of them do not conform to Codecademy's instructions, you'll see an "Oops" message.


#5

HI.. I am getting same 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".

Not sure what variable am I naming incorrectly ! Can someone please help on this....

import math
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 = float(sum(numbers))
avg = total / len(numbers)
return(avg)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
total = 0.1*homework + 0.3*quizzes + 0.6*tests
return(total)

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))
print results
return average(results)

print get_average(lloyd)
print get_average(alice)
print get_average(tyler)

Students = [lloyd,alice,tyler]

print get_class_average(Students)
print get_letter_grade(get_class_average(Students))


#6

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