9/9 How is Everybody Doing?


#1


Error 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

P.S.
If I add a line
" students = [lloyd,alice,tyler] "
and replace the last two lines with
"
print get_class_average(students)
print get_letter_grade(get_class_average(students))
"
It works.
I wonder what's the difference between these two codings.


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"])
    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"
print get_letter_grade
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]))


Hi Guys mine is still not working even thogh the code seems to be same
#2

I think the students list is part of a test codecademy uses to determine if your code is correct.

There shouldn't be a difference in functionality.


#3

All right . Thanks a lot !!


#4

Help please! My code is as follows but still keep getting error even though I think i follow every step according to the instruction! Thanks beforehand!01!

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):
total = sum(numbers)
total = float(sum(numbers))
return total/len(numbers)
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 get_letter_grade(get_average(llyod))

def get_class_average(students):
results = []
for student in students:
get_average(student)
results.append(get_average(student))
return average(results)
print get_class_average([llyod, alice, tyler])
print get_letter_grade(get_class_average[llyod, alice, tyler])

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


#5

The student list @ajaxsolver72071 mentioned is missing from your code.


#6

I added the list but still it does not work.

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):
total = sum(numbers)
total = float(sum(numbers))
return total/len(numbers)
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 get_letter_grade(get_average(llyod))

def get_class_average(students):
results = []
for student in students:
get_average(student)
results.append(get_average(student))
return average(results)
print get_class_average([llyod, alice, tyler])
print get_letter_grade(get_class_average([students])

File "python", line 49
print get_letter_grade(get_class_average([students])
^
SyntaxError: invalid syntax


#7

Here's my opinion:
In my coding, i "build" students(which is a list) ,using the following line --> students = [llyod,alice,tyler]
but it seems that there is not such line in your coding.
As a result , the system doesn't know what students is when you call it by using get_class_average .

You can see how I correct my coding above. Hope it will help you:)


#8

Still does not work.

Finally, print out the result of calling get_class_average with your students list.

print get_class_average([lloyd, alice, tyler])

I assign
students = [lloyd, alice, tyler]

Then, print the result of get_letter_grade for the class's average.

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

but still doesn't work.

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

thanks for your help!


#9

haha ! The problem you are facing is exactly the one I was having.
According to @eveat, there is no functional difference between

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

and

print get_letter_grade(get_class_average(students))

but Codecademy seems to try to ensure that learners know how to use the students when calling a function.
In other words, the students is like the keyword to complete this coding.

As a result , you should use
print get_letter_grade(get_class_average(students))
instead of print get_letter_grade(get_class_average([lloyd, alice, tyler]))


#10

Thanks ajaxsolver72071 ! i am glad it is figured out! good luck with coding.


#11

Thanks,
Had the same problem. It all worked perfectly when running it useing IDLE, but codecademy keeps rejecting it.
After using your tip codecademy finally accepted the code.


#12

Hi ajaxsolver72071,

I have written the following code and getting the output. I have checked my code quite a number of time and tried making changes but the error in output is being observed.

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!

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"

get_letter_grade(lloyd)
print get_letter_grade(get_average(lloyd))

def get_class_average(students):
results=[]
for students in students:
results.append(get_average(student))
return average(results)
students=[lloyd,alice,tyler]
print get_class_average(students)
print get_letter_grade(get_class_average(students))

OUTPUT:
Traceback (most recent call last):
File "python", line 54, in
File "python", line 51, in get_class_average
NameError: global name 'student' is not defined


#13

IN the get_class_average function:

I guess you meant to write for student in students.


#14

Thanks for the reply and I have rectified the line that you have highlighted but I am getting the following output:
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


#15

Hi, everyone ,

Make sure you format your code when you post it, so that we can see indentation and other details. Otherwise, we cannot determine the block structure of your code as we check it over.

The following statement assigns the list of student dictionaries to the variable, students, and must be outside all of the functions, so that the variable is global. Codecademy checks to make sure you have defined such a global variable. If you have not, you will see the following message that several have reported in this thread ...

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

For the variable to be defined globally, make sure that the statement is not indented, otherwise, you may have inadvertently made the statement part of a function.