9/9 Error message


#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 = float(sum(numbers))/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_class_average([lloyd, alice, tyler])

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

When I submit the above code this shows up in the console:

83.8666666667
B

Though I also receive the error message:

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


#2

I had a REALLY hard time with that, too. The problem, first, is that you should replace all your

to students, or like:

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

Then, I can explain much easily.

Now, your code should be something like this:

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

In the print section, I mean. What I did not know is that you have to define students again. So, I had to make an array for students, with the actual students (tyler, lloyd, alice).

students = [lloyd, alice, tyler]

Hope it helped!:smiley:


#3

Thanks, that did the trick. :smile:


#4

Hi All,

Really stuck on this - cannot get it to work no matter what I try:

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

indent preformatted text by 4 spaces

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(total)
total = total / len(numbers)
return total

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])

total = (homework * 0.1) + (quizzes * 0.3) + (tests * 0.6)
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"

print get_letter_grade(get_average(lloyd))

students = [lloyd, alice, tyler]

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

    print get_class_average(students)
    print get_letter_average(get_class_average(students))

it comes up with the 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

I am tearing my hair out here - can anyone help????


#5

Oops - that last line should be

print get_letter_grade(get_class_average(students))


#6

It still doesn't work though!


#8

result

students must be student


#9
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'
    print get_letter_grade[get_average(lloyd)]


def get_class_average(students_group):
    results = []
    for floatzel in students_group:
        results.append(get_average(floatzel))
    return average(results)
    
students = ['lloyd', 'alice', 'tyler']

print get_class_average(students_group)
print students = ['lloyd', 'alice', 'tyler']
print get_letter_grade(get_class_average(students_group))`indent formatted text by 4 spaces`

I saw how you helped with this problem or similar before and was wondering if you could give me some guidance.


#10

That still doesn't work, it gives the 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

My code is now as belowindent preformatted text by 4 spaces

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_average(get_class_average(students))

#11

You made the wrong array:

Since you put students_group, you have to make an array called students_group, not students.

students_group = [,,___]

Also, you must change the order of your codes here:

Why? How can you use an array if you didn't define it yet, and you define the array after that function? To be more specific, look:

I made your quote look as if you made a students_group array. Anyways, you used students_group, but you only defined students_group after that. So, that

print get_class_average(students_group)

does not know what students_group is! So, you need to switch places with those two statements.

Hope it helped!:smiley:


#12

Please read the last part of what I have said to gregpope:


#13

@james010
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))

check if there are indents in last two print statements.. your code worked perfectly for me with correction


#14

This worked for me.....and a massive Thank You to all that have posted. I still get confused, It takes me ages and i sometimes need to use paper and pen to work out some of the flows. I also now use the </> button above as somebody suggested so you can see the identations. Chin up, onwards and upwards........:smile:

def get_class_average(students):
    results = []
    for student 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))