Error in the code! Why? Help please!


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]

students = [lloyd, alice, tyler]

for student in students:
print "name: %s" % students[student:"name"]
print "homework: %s" % students[student:"homework"]
print "quizzes: %s" % students[student:"quizzes"]
print "tests: %s" % students[student:"tests"]


What's the problem?

Note that indentation is significant in Python and therefore needs to be included when you post your code (otherwise you're posting something else)


I used the indentation in my exercise!

But it doesn't work..

The error is: Your code looks a bit off--it threw a "slice indices must be integers or None or have an index method" error. Feel free to peek back at earlier exercises if you need a syntax refresher!

What I should do?


Which is why we should see it as well, otherwise we're looking at something other than what you used, you see the problem, right?

Your error message mentions slicing which you shouldn't be doing at all, remove the colons from between your []'s and consider what you meant to do there and how that's done.

Also, why did you put the colons there? Avoid guessing, look things up instead. Writing code is to describe what the computer should do. The computer does exactly as that description says, so you gotta write exactly what you want it to do - you have to understand every piece you're writing. Always gotta back up what you write with an argument about why it's right.

A student is represented by a dictionary. What operation do you want to do with that dictionary in that location? How is that operation done? How can you find out?


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