Hi,
I have a piece of code with the following type error:
Many thanks
I have a piece of code with the following type error:
Error:TypeError: string indices must be integers, not str
I am new to Python and got stuck in my code. Would you please help me figure out whats the problem?Many thanks
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 get_average(student): homework = 0 quizzes = 0 tests = 0 for key in student: homework =sum(key["homework"])/len(key["homework"]) quizzes = sum(key["quizzes"])/len(key["quizzes"]) tests = sum(key["tests"])/len(key["tests"]) res = 0.1 * homework + 0.3 * quizzes + 0.6 * tests print key["name"], float(res) student = [alice,tyler] get_average(student)