Sending a Letter - Wrong Grade Displayed


Hi All,

When I run my code, the output shows the student got an "A", but should have a "B". What didn't work? It displays a grade average 80.55.
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)
total = total/len(numbers)
return total

def get_average(student):
homework = average(student["homework"]) * .10
quizzes = average(student["quizzes"]) * .30
tests = average(student["tests"]) * .60
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"
return "F"
return get_average(lloyd)
print get_average(lloyd)
print get_letter_grade(lloyd)


get_letter_grade() converts a number grade into a letter grade

so you should fist calculate the average grade (use get_average() ) and supply that as argument for get_letter_grade


I am confused. What would that look like and how would that code work?


calculate a student average grade (with get_average, you should be able to do this, given you have already done this), then there are two options: store the average grade in a variable and supply this variable to get_letter_grade, or call get_average inside of get_letter_grade


How do I use my current code to obtain that, rather than writing different code?


well, you already call get_average:


so you could store the result of this function call in a variable, and supply this variable as argument for get_letter_grade


Reading this, i am not sure how to store the result in a variable. Would this work?

grade_average = get_average(lloyd)


yep, very good. Now we can supply grade_average as argument for get_letter_grade()


I started this section Saturday and trying to get back into that mindset hasn't been easy. My confusion is trying to follow the directions for "Part of the Whole" and where to insert your suggestion. This section has me questioning if I have learned anything to this point.


we are talking function calls here, which are your last 3 lines or so

Yep, its difficult to comprehend. Been there, first time i saw this i was like: i don't understand any of it. Now i do, so yep, you learn something :slight_smile:


The directions for the exercise are:
1. Define a function called get_class_average that has one argument students. You can expect students to be a list containing your three students.
2. First, make an empty list called results.
3. For each student item in the class list, calculate get_average(student) and then call results.append() with that result.
4. Finally, return the result of calling average() with results.

Do i make a new block of code or add to an existing block?

If I start a new block, this is what I am thinking the directions want:

def get_class_average(students):
results = []
for i in students:
return get_average(students)

I am not sure if that is in the right direction.


yep, you get the average of students, now you will need to append this to results list

then you need to return the average() of results list


I inserted the following code into the section and clicked save/submit. I get the error - File "python", line 50
for i in students:
IndentationError: expected an indented block

def get_class_average(students):
results = []
for i in students:
return get_average(students)

Based on your reply,

results.append(get_average) ?


why when you go from return get_average(students) to results.append(get_average) why do you remove `(students)? get_average is still a function call, it should still have parentheses and a argument.

also, your get_average() is designed to calculate the average grade for a single student. (hint: loop, students is a list with students)


I changed students to get_average to put the result of a function in the result list. I went through my code and do not have a list for students. What role does an argument play when defining a function or calling a function?

Do know of a resource that explains how and why things are done in Python?


you should have? you build the list in 3. put it together of this track (student become teachers)

if you don't have it, its alright, the exercise will supply arguments when its calling the function. Till the function is called, the parameter is just a placeholder.

everything so far should have been taught? Python also has official docs and there also wiki's, and other sources


I went back and found the student list, it didn't copy through to the next sections. When using students as an argument, does that automatically pull the names in the list "students"?


no, you will have to supply students list as argument when calling the function

like i said, a function parameter is a placeholder until you supply an argument calling the function


I need to review that. I understood that when I originally went through it, but that was a while ago.

BTW, I really appreciate your assistance!


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