• Register
1 vote
1.9k views

Problem:

I am a beginner in python programming language. I tried to create a program to calculate my students avarage results so I wrote this code
porter = {
    "name": "Porter",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
arnub = {
    "name": "Arnub",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
opir = {
    "name": "Opir",
    "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)
    avg=total/len(numbers)
    return avg

def get_average(student):
    homework=average(student["homework"])
    quizzes=average(student["quizzes"])
    tests=average(student["tests"])
    res=0.1*homework+0.3*quizzes+0.6*tests
    return res

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(porter))

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

But it shows error message

"Oops, try again. getclassaverage([porter]) resulted in an error: 'list' object attribute 'append' is read-only"

Can anyone help me out to solve this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote

Answer:

You are getting this error because of the line

results.append=get_average(student)

You should change the line to

results.append(get_average(student))

Hope if you change the line your code should work properly.

Happy coding.

11 6 4
34,950 points

Related questions

0 votes
1 answer 76 views
76 views
Problem: The following error message is displayed: “Oops, try again. get_class_average([alice]) resulted in an error: ‘list’ object attribute ‘append’ is read-only” This 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] }
asked Feb 18 Mashhoodch 13k points
0 votes
1 answer 15 views
15 views
Problem: Hello! I am wondering whether it is possible to append a list to another list in Python or not? What I mean is, suppose I have a list named list1 and have values such as [1,2,3,4,5]. I have another list named list2 having the values [6,7,8,8,9]. Is it possible to append list1 with list2 or vice versa? If yes, how?
asked Mar 24 Code Learner 9.8k points
0 votes
1 answer 22 views
22 views
Problem: as the title says, in python, I'm trying to make it so when someone types in a choice (in this case Choice13) then it deletes the old password from the list passwords and adds the new one instead
asked Feb 18 Mashhoodch 13k points
0 votes
1 answer 2 views
2 views
Problem: Can some body tell me about this problem? Attributeerror: 'nonetype' object has no attribute 'append'.
asked 3 days ago PkGuy 23.5k points
0 votes
1 answer 7 views
7 views
Problem: When I run this code then following error is encountered, I am new to programming and I know I have bunch of useless arrays. I don't know where my error is as I have declared j as an array. I am completely out of ideas. Help me resolve this please.
asked Apr 20 munim01 21k points
0 votes
1 answer 893 views
893 views
Problem: Recently I have joined new project on python and numpy. My below code is returning me below error: Attributeerror: 'numpy.ndarray' object has no attribute 'append' . Please find my code below for the reference: class1 = np.array([]) #It creates 2 ... to print my results in the scatter graphic with the two colors where I can try to identify the visually the class1 and class2 elements.
asked Jun 17, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 32 views
32 views
Problem: I am new to python. Can anyone help me out? How to delete a list in python? Thanks!!
asked Mar 5 Samiur1 38.4k points
1 vote
1 answer 348 views
348 views
Problem: I have been doing programming for a while and I am using python for this. So my question is What is an advantage of using a tuple rather than a list? Thank you
asked Apr 6, 2020 LizzyM 6.1k points
0 votes
1 answer 8 views
8 views
Problem: When i opened my pc then i seen that python list of all files in directory and subdirectories. Can anyone know about this then please answer me.
asked Mar 27 niyatiry 3.9k points
1 vote
1 answer 14 views
14 views
Problem: Any clue how to slove this calculation? Multiply all values in a list python.
asked Mar 26 PkGuy 23.5k points