11.8 - Unsupported operand type


#1



Let me start out by first stating that I have read through a dozen posts comparing my code to what everyone else has posted. Besides some difference in variable names, my code looks identical.

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


My code throws the following error:

Oops, try again. get_class_average([alice]) resulted in an error: unsupported operand type(s) for +: 'int' and 'NoneType'

I've compared the functions to what others have posted and it seems correct.


 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))
     total = total / len(numbers)
     return total
     
 def get_average(student):
     homework = average(student['homework'])
     quizzes = average(student['quizzes'])
     tests = average(student['tests'])    
     score = ((homework * .1) + (quizzes * .3) + (tests * .6))

 def get_letter_grade(score):
     if (score >= 90.0):
         return "A"
     elif(score >= 80.0 and score < 90.0):
         return "B"
     elif(score >= 70.0 and score < 80.0):
         return "C"
     elif(score >= 60.0 and score < 70.0):
         return "D"
     else:
         return "F"
        
 def get_class_average(students):
     results = []
     for pupil in students:
         results.append(get_average(pupil))
     return average(results)

Any help would be much appreciated.


#2

This function needs to return the score.

return homework * 0.1 + quizzes * 0.3 + tests * 0.6

#3

Why should I use "print get_average(tyler)" to print the result???

Wont the function return the value???


#4

The function only returns the value. To view the returned value we print it.


#5

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