students = [lloyd, alice, tyler]
print get_class_average(students)
print get_letter_grade(get_class_average(students))
I get a message: 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. What does it mean?
If I indent the code you have submitted and run it, your functions works:
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 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"
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
print get_letter_grade(get_average(lloyd)) # returns "B" as expected
print "Lloyd's average is: " + str(get_average(lloyd))
print "Alice's average is: " + str(get_average(alice))
print "Tyler's average is: " + str(get_average(tyler))
# Returns
# Lloyd's average is: 80.55
# Alice's average is: 91.15
# Tyler's average is: 79.9
print get_letter_grade(get_average(lloyd))
print get_letter_grade(get_average(alice))
print get_letter_grade(get_average(tyler))
# Returns
# B
# A
# C
But I see you have no code to fulfil the two assignments for the lesson your help request is associated with (Lesson 11, 9/9):
Instructions
Finally, print out the result of calling get_class_average with your students list. Your students should be [lloyd, alice, tyler].
Then, print the result of get_letter_grade for the class’s average.
You can use the formatting trick I mentionned in a previous post or you can use the button that looks like </> in the editor’s toolbar. Both will have your pasted code rendered with proper indentation.
Sometimes errors are in the indentation itself so it is important to be able to see it to help troubleshoot properly.
You’ll notice that russharold does define his list of students and prints get_class_average and get_letter_grade for that average in his first post.
I have identical code to russharold, which is complete and executes correctly in the console. The only problem seems to be Code Academy’s interpretation of the code and this Code Academy error message. The previous step 8/9 executed correctly and was passed by Code Academy and the console. The only lines added were the following:
I also get an error identical message: “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.”
The strange thing is, that if I comment out all of the new lines added since step 8, I get the same error message. This tells me that I am not reading a Python interpretor error message, but a Code Academy error message.
Still none the wiser. It may be a typo, or indentation problem, or unmatched brackets, but I cannot find the error.
I fixed my error by changing the name of my students list to students instead of class_students. I’m not convinced that the error is anything more than pedantic nit-picking by the Code Academy program. The list being passed is a parameter and could be named anything under the sun.
My guess is that when we hit “Save & Submit Code”, our input probably gets parsed and analysed by a python script.
As you may or may not know, humans are slow and smart and computers are fast and dumb.
That being said: Never expect a computer to “understand” that what you are doing is “roughly the same” or even “better” than what it has asked you to do. Have a look at this post if you need a proof of that…
Now from your code I can see that you did not call your student list students but class_students instead.
If the python script analysing your code is looking for a variable named students… I’m sure you can see where this is going.
Your two print statements also are very nicely formatted and readability for a human eye is perfect. Unfortunately, the instructions where to simply print get_class_average on your student list, and then get_letter_grade of that get_class_average.
So…
students = [lloyd,alice,tyler]
print get_class_average(students)
print get_letter_grade(get_class_average(students))
Many have finished this entire Python Introduction course so you can assume that every lesson “works”.
Every time you’ll stumble on an error, start by asking yourself “Am I doing exactly what this dumb machine is expecting me to do?” or more precisely “Am I giving it exactly what it is asking me for?”
In a regular class, with a human teacher evaluating assignments, I’d say you’re right!
But the more you work with computer code, the more you will see that being scrupulous, precise, exact, perfectionist, punctilious, meticulous, fussy, fastidious and finicky are not flaws but actually qualities almost necessary to a programmer…
Actually I have been a programmer for 35 years, and used many programming languages. Pedantic and nit-picking are not the same thing as scrupulous, precise, exact, perfectionist, punctilious, meticulous, fussy, fastidious and finicky. In my opinion the instructions are not written as clearly as many of the other steps previous to step 9/9.
The step 9/9 mentions the list “students”. Students is also a pre-existing parameter variable of type list for the function get_class_average from step 8/9. The list variable and parameter variable of type list, in my opinion, should not have the same name, since they are different things entirely with the only the same type definition in common. Good practice would be to name the list variable containing content something more precise than just students, and leave the parameter variable with the more general name students.
with the list as so, but once I assigned the list to students
and called get_class_average(students) with the variable instead, my code passed. Go figure.
Hi @faz, I’ll be glad to help if you post your code using the trick described here. When you do, your code retains its proper formatting and it makes it quite easy for use to analyse it