# Attributeerror: 'list' object attribute 'append' is read-only

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

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)``````

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?

1 vote

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.

## Related questions

76 views
Problem: The following error message is displayed: &ldquo;Oops, try again. get_class_average([alice]) resulted in an error: &lsquo;list&rsquo; object attribute &lsquo;append&rsquo; is read-only&rdquo; 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] }
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?
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
2 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.
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.
32 views
Problem: I am new to python. Can anyone help me out? How to delete a list in python? Thanks!!
1 vote