• Register
1 vote
1.5k 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 18 views
18 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 9.9k points
0 votes
1 answer 10 views
10 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 9.9k points
0 votes
1 answer 759 views
759 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
1 vote
1 answer 254 views
254 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 331 views
331 views
Python 3.3.2 import json & urllib.request Json [{"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}] print(response.info()) Date: Sun, 20 Oct 2013 07:06:51 GMT Server: Apache X-Powered-By: PHP/5.4.12 Content ... line 271, in load return loads(fp.read(), AttributeError: 'str' object has no attribute 'read' >>> . Any idea how i can fix this issue?
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 29 views
29 views
Problem: I have a small problem with list. So i have a list called l: l = ['Facebook;Google+;MySpace', 'Apple;Android'] And as you can see I have only 2 strings in my list. I want to separate my list l by ';' and put my new 5 strings into a new list called ... tried to do this like this: l1 = l.strip().split(';') But Python give me an error: AttributeError: 'list' object has no attribute 'strip'
asked Feb 13 Mashhoodch 9.9k points
0 votes
0 answers 174 views
174 views
function anagrams(s1, s2) is a Boolean valued function, which returns true just in case the string s1 contains the same letters as string s2 but in a different order. The function should be case insensitive --- in other words it should return the same value if any letters in either s1 or ... ; Ayxan Haqverdili Nov 12 '18 at 15:43 I've no idea..... maybe my logic is wrong, the output is so wired...
asked Oct 25, 2020 psandprop 2.4k points
1 vote
1 answer 787 views
787 views
Problem: Hello all, I have started learning python recently. I installed python 3.2 on my Linux machine. I come to know about a function .clear() that clears the value inside a list. I am trying to clear the values of my list but it&rsquo;s not working for my case ... () Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'list' object has no attribute 'clear'
asked Apr 5, 2020 Gavin 15.3k points
1 vote
1 answer 3.2K views
3.2K views
Problem: I have a dictionary with some users' data in it. Trying to use the dictionary to call with .append() function but it throws an error that says attributeerror: 'list' object has no attribute 'keys' But I haven&rsquo;t declared it as a list in my program. Where am I doing wrong? Could ... = {} n = 0 for i in dict.keys(): new[i] = entry(n) n += 1 dict.append(new) Many thanks for your help.
asked Apr 5, 2020 Gavin 15.3k points
0 votes
1 answer 10 views
10 views
Problem: How can I find all the files in a directory having the extension .txt in python?The pathlib module was included in the standard library in python 3.4. But you can install back-ports of that module even on older Python versions (i.e. using conda or pip): pathlib and pathlib2.
asked Feb 19 Mashhoodch 9.9k points