9/9 How is Everybody Doing? Missing or Borken


#1

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


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

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

return 0.1 * average(student["homework"]) + \
0.3 * average(student["quizzes"]) + \
0.6 * average(student["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):
restults = []
for student in students:
get_average(student)
results.append(get_average(student))
return average(results)

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

print get_letter_grade(get_class_average(students))


#2

@halifaq I see a couple of things that I did different there, for example,

1)this is how I put the get_average method together:

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

2) I also see a typo in your get_class_average method, not sure if you had the same error within your live editor. "results" was misspelled as "restults".

3) at the very end, all I did was the below line of code to get the average grade for all 3 students, now that you have a list for all of them called "students":

print get_letter_grade(students)

#3

Hey!

As I can see, there is nothing wrong with your code, meanwhile make sure you have proper indentation in your code.
Here's mine code, it works just fine. Take a look-

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"]) * 0.1
quizzes = average(student["quizzes"]) * 0.3
tests = average(student["tests"]) * 0.6

return homework + quizzes + 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(lloyd))

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

I hope it helps. Cheers! :smile:


#4

please help me understand what are the mistakes in the following 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)
return total/len(numbers)

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

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(lloyd))

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

class_average = get_class_average([ alice,lloyd, tyler])

print(class_average)
print(get_letter_grade(class_average))


#5

Hey!

Check the code below, I made some changes in you code and whatever I did remove from your code is in comments.

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'])
value = homework * 0.1 + quizzes * 0.3 + tests * 0.6
return value

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(lloyd))
print get_letter_grade(get_average(lloyd))

def get_class_average(students):

#results = list()
results = [] 

for student in students:
results.append(get_average(student))
return average(results)

#class_average = get_class_average([ alice,lloyd, tyler])
students = [lloyd, alice, tyler]

#print(class_average)
print get_class_average(students)

# print(get_letter_grade(class_average))
print get_letter_grade(get_class_average(students))

Try this and don't forget to indent your code.
I hope it helps! :smile:


#6

thank u so mch bro...
can plz tell me what we have done in this code?
im little bit confuse