# Part of the Whole

#1

Oops, try again. get_class_average([alice]) resulted in an error: 'NoneType' object is not iterable

I'm noit understanding what's wrong, please suggest if something's not right

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

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

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 = [lloyd, alice, tyler]):
results = []
for keys in students:
get_average(keys)
results = results.append(get_average(keys))
return average(results)``````

#2

Reproduce the crash with the input it shows you. That'll give you a line number for where the crash occurs so that you can then start making observations about what it is you're attempting to do there in order to compare what happens to what you mean for to happen.

#3

here's the error

Oops, try again.
get_class_average([alice]) resulted in an error: 'NoneType' object is not iterable

No line number

#4

Hi All,

it seemed to have worked however not understanding

why my code doesn't run when I use

result = results.append(get_average(keys))
return average(results)
???

#5

now even when "I used teh below

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)

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

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 = [lloyd, alice, tyler]):
results = []
for keys in students:
get_average(keys)
result = results.append(get_average(keys))
return average(results)
print average(results)

It worked fine

#6

It's giving you an example of where it crashes. Try to run the same example and look at the resulting error message

#7

it's run thois time fine without errors just not understanding wht's wrong ?

if with teh editor or what but teh same code failed several rimes and later it just worked

crazy

#8

Can't tell if you're asking anything any more.

Things don't just "suddenly work", sounds more likely that you just weren't testing the thing where it was misbehaving. It's like saying that a washing machine isn't broken, because nobody is trying to use it. That isn't a good indication, instead you would try washing something.

#9

got it !! used results n in the next I used result where it worked

got error when used

results = results.append(get_average(keys))
return average(results)

and worked when

result = results.append(get_average(keys))
return average(results)

#10

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

This is what worked for me

#11

I am getting this error:

"Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected"

I do not understand why this is the error. Here is my 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]
}

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 * homework + 0.3 * quizzes + 0.6 * tests
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 average(results)``````

#13

Can someone explain to me why indenting the return statement at the end was why I had an error?

#14

the end part of the code -
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
print average(results)

#15

I've fixed my error -after reading this message you wrote. What I understand is this:
get_class_average function is supposed to return the result of average(results) , not the for loop.

the for loop here is just to get values for the results list (the built-in append function already kind of "return" the result of get_average(student) to the results list.

#16

Thank you

This message was sent from the MacSide

#17

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