9.- How is Everybody doing?


#1

When I Save & submit code, it gives the result:

83.8666666667
B
None

Which seems to be OK. But I Receive a problem which says:

"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 the following:

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


def get_average(student):
    homework = average(student["homework"]) 
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    
    return .1 * homework + .3 * quizzes + .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 x in students:
        get_average(x)
        results.append(get_average(x))
    return average(results)
    
classList = [lloyd, alice, tyler]

print get_class_average(classList) 
print get_letter_grade(get_class_average(classList))

#2

No way!!! It worked perfectly for me!


#3

That's what I mean, I'm not sure if it's possible, but maybe my account is kind of bugged? haha I really have no idea...


#4

If you change classList to students it will work....guess the course is looking for that keyword


#5

I have the same issue..what is going on?? :stuck_out_tongue:


#6

Did you fix it somehow? Since we don't have something wrong in our code..


#7

@regi88 I solved it as @kevin_osullivanammeo said, I just replaced the name of my list (ClassList) to students, and it worked. Thanks


#8

I am also having same issue


#9

@rodrigozd While this is the fix in this case, I don't think it's technically proper. From how I see it, the problem with that is that you're passing a parameter (students) to a function (get_class_average) that is also a predefined "regular/global" variable (might be using the wrong terminology).

Using the same "local variable" for a function as a regular/global variable is a bad practice as it can cause obscure problems if you don't catch it, although it doesn't in this case as they are referring to the same thing and not modifying the stored value(s). This is unless Python handles things differently than what I'm used to.

Also, with "students = [lloyd, alice, tyler]" the function get_class_average() will work just as well in this way, with no parameter passed to the function.

Basically, we should do this:

classList = [lloyd, alice, tyler]

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

But it's forcing us to do this:

students = [lloyd, alice, tyler]

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

Does that make sense, and am I correct in how Python handles variables and variables as parameters?


#10

I kind of get your point. It's not a good programming practice to use the same (or even closely identical) names for arguments as parameters, since it'll be easy to confuse those and for the worse, it might lead to bugs that are hard to debug when the circumstance comes. And, it's not just in Python, it's the same for every other programming language in active use. Anyway, I think it's the way the courses are designed to work that forces us to do these insert your not-so-negative adjective things. I had a similar experience with the Python course, where I wasn't allowed to take some approaches to perform a basic task, like printing a variable string in a variety of ways. Here it is, (no replies, though): http://discuss.codecademy.com/t/questions-for-8-keeping-track-of-the-produce-13/12587


#11

The comments made by users concerning the need to not confuse local and global variables are quite valid. In general, functions should not access global variables directly, because it can make programs confusing and difficult to debug, but there are exceptions. For example, if a program were written that contains several functions, each of which needs to work with a huge list of prime numbers, it might be advisable to maintain one global list of prime numbers that all the functions share through a global variable. However, that is not the situation here. For this exercise, each function would best be designed to receive the data through arguments and parameters.

As for this 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

... Codecademy wants you to have this statement in your code, so that you have a global variable, students ...

students = [lloyd, alice, tyler]

The statement was created for Exercise 3: Put It Together, but sometimes it gets lost along the way.


#12

Wholeheartedly agree with your statements about globals. If I remember correctly, in a C++ class I took back in high school, I actually used a function to modify a global throughout several phases of my program. That was essentially the only time in my limited programming experience that I have done so, however.


#13

The code is all good but the code checker might be looking for specific words to pass it, as said by @kevin_osullivanammeo, so just change classList to students and the code will surely work!


#14

Check with this......

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"])
get_average = homework * quizzes * tests
return homework * .1 + quizzes *.3 + tests *.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"

return get_letter_grade

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

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


#15

I've got error adding the last part of code as below:def get_class_average(students):
results=[]
for student in students:
results.append(get_average(student))

print student

print results

return average(results)

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


#16

Hi!

I was having the same issue as everyone else, and I got the error message that something was missing. I spent hours trying to figure it out, but I kept getting the same error. I had already changed the name of the list to students, but I got the same error. What worked for me was taking out the quotation marks around the three name strings in your students list. It looked like this:

students = [lloyd, alice, tyler]

That seemed to work for me. I don't know why, since it had worked on every previous lesson. Thanks and I hope this helps!


#17

I read through a lot of answers to this excercise in a lot of different post and there seems to be some different resolutions. I am still going to add my two cent here because you guys are helping me learn and i hope my post does the same for others... here goes...

my code was this(minus the "ticks)

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

I was getting this

after combing through resolutions I did this (commented the line completely out)

that got me one of these! (High fives, pats on the back all that... WhooHoo!)

But then i got to thinking... WHHHHY was it that simple????!!!!!!!! So I read the exercise again and found this in the 1st instruction

Yes the list I (most of us have) created is already assumed to be created so this DOES NOT need to be part of your coding. (At least that is how I understanding it)

If I'm wrong, i apologize now and for future code learners who may read this, but this is at least the second time I have doubted myself over a simple attention to detail in following instruction...

Again thats just my two cent. HOPE IT HELPS!

Nate G


Part of the whole-8
#18

Please somebody tell me what is wrong with this code, and I don't really know what im doing, so in laymans terms please

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)
return float(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"])
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)


#19

Could you guys help me understand a thing?!

Well, my doubt is:

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

Why does it print it:

A
83.8666666667
B

I mean..is this somehow linked to the get_letter_grade(score) thing?
I asked for the class average, with only numbers right?
Then, asked for the letter for class' score right?

So, what is that freaking A in there?

Tks for helping by the way :slight_smile:


#20

This is what I did to compile without any error!

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]
}

students = [lloyd, alice, tyler]# Add your function below!
def average(numbers):
total = sum(numbers)
total = float(total)
avg = total / len(numbers)
return avg
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
weighted = (0.1*homework) + (0.3*quizzes) + (0.6*tests)
return weighted
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(get_average(lloyd))
def get_class_average(students):
results = []
for student in students:
result = get_average(student)
results.append(float(result))

return average(results)

print get_class_average(students)
one = get_average(lloyd)
two = get_average(alice)
three = get_average(tyler)

print get_letter_grade(one)
print get_letter_grade(two)
print get_letter_grade(three)

Output:
83.8666666667
B
A
C
None