9. How is Everybody Doing?


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/5?curriculum_id=4f89dab3d788890003000096


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
script.py
Traceback (most recent call last):
File "python", line 69, in
NameError: name 'student' is not defined


I just don't understand what I've got wrong


Replace this line with your code. 
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_grade(get_class_average(students))


#2

look at this line again:

wouldn't that just append:

students = [lloyd, alice, tyler]

#3

what do you mean when you say that?


#4

look at the for loop:

it says for student not students

so you would be appending the students list to results


#5

is this any better?

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

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


#6

Yes it is exactly right! The code should work now. :slight_smile:


#7

I'm not sure I understand can you please show me what its supposed to look like and then explain why?


#9

@steven.copeland, Not posting answers also includes the personal messages.

@coder_theo, can i see your full code?


#10

okay that would be good do that then


#11

this is my full 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) / len(numbers)
    return total

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

#12

Is it okay if I show him the s trick? Because his code works now.


#13

what is the s trick?


#14

your students list:

students = [lloyd, alice, tyler]

should be outside the function. you can pass students as argument when you call the function.

here:

for students in students:

you loop over students list.

but your iterator is the same the list you loop over, the iterator should be student since it gets assigned a single student (in sequence from the list)

here:

print get_letter_grade(get_class_average)

get_class_average is a function call, the parentheses + argument are missing


#15

I just don't get it I've tried it and it doesn't work so I'm not sure what to do could you please explain in the simplest terms possible because I don't understand


#16

this is my most updated code what needs to change and how?

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

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


#17

can i see an updated version of your code?

3 three things need to happen,
1. you need to change the place of the students list
2. in get_class_average, change the loop iterator to student
3. get_class_average(students) should be the argument for get_letter_grade()


#18

I've tried that and it didn't work:

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

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

#19

How is student not defined?
Traceback (most recent call last):
File "python", line 68, in
NameError: name 'student' is not defined


#20

students is still inside your function? It should be outside the function. for example here:

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

now you can supply students as argument when calling get_class_average

you should call get_class_average twice, once to print the class average and once to print the letter_grade of the class average.


#21

Thank you so much i finally completed it and sorry for being a pain by constantly asking questions and not understanding this is my first time creating a topic and I'm glad it worked so thank you