9.How is every body doing?


#1

Continuing the discussion from 8. Part of Whole, returned average as 91.15 instead of 85.85 expected:



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


#2

HI try to put this line

students=[lloyd,alice,tyler]

before the function get_class_average()


#3

That makes no difference. It only needs to exist by the time it's used (python being dynamic) and it isn't referenced at all from the function.

@varunks just go through the list of those names and see if they contain what they should. You've probably removed, renamed or changed something.


#5

It worked by creating the List students( students=[lloyd,alice,tyler] ) . Just wondering why do we need to create a list here. We can directly pass the list as arguments.


#6

I wondering the same.
Why I can't use code just like below:

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

#7

Try this:

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

Embedding is handy, and if you hate extraneous stuff...they're fun.And you can just copy paste from line 2 to line 3. Effective laziness.


#8

can you submit the code please?


#10

print get_class_average([lloyd, alice, tyler])
for student in [lloyd, alice, tyler]:
print_ get_letter_grade(get_average(student))

AND code below


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

What's difference between these pieces of code?


#11

Using print get_letter_grade(get_class_average(students)) worked for me without declaring the lists. See section below:

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

#12

So my declaration of get_class_average is bit different but works with code in spoiler:

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