Lloyd! Get in my dictionary


#1

Could someone please help with the code

this is what i have so far

lloyd = {
"name": ["Lloyd"],
"homework": [],
"quizzes": [],
"tests": []
}

alice = {
"name": ["Alice"],
"homework": [],
"quizzes": [],
"tests": []
}

tyler = {
"name": ["Tyler"],
"homework": [],
"quizzes": [],
"tests": []
}

for key in lloyd :
print lloyd ["name"]
for key in alice :
print alice["name"]
for key in tyler :
print tyler["name"]


#3

I had this trouble, you need to take the [ ] from around Lloyd (and all the others) I don't know why seeing as how the example shows the [ ] but it works!


#4

thats not very nice m89


#5

Having the same problem. Getting really frustrated. I've tried it with brackets. I've tried it without brackets. Why does it keep telling me: "Oops, try again. The name key does not have the value "Lloyd" in your lloyd dictionary"

lloyd = {
"name":"LLoyd",
"homework":[] ,
"quizzes" : [] ,
"tests" : []
}

alice = {
"name": "Alice",
"homework" : [] ,
"quizzes": [] ,
"tests": []
}

tyler = {
"name" : " Alice",
"homework" :[],
"quizzes" : [] ,
"tests" : []
}


#6

the best way to do it is to understand how the for function works.
try to read it like this,

for x in students

this means for every item in the list students I'm choosing to call this item x for now. now you are telling the code what to do with each item (x) in the students list.

print x['name']

now the code will replace x with an item in students each time it runs. so it will go with lloyd and alice and then tyler.
your final code should be

lloyd = {
"name": "Lloyd",
"homework": [],
"quizzes": [],
"tests": []

}
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]
}
lloyd["homework"]=[90.0, 97.0, 75.0, 92.0]
lloyd["quizzes"]=[88.0, 40.0, 94.0]
lloyd["tests"]=[75.0, 90.0]
students=[lloyd,alice,tyler]

for x in students:
print x['name']
print x['homework']
print x['quizzes']
print x['tests']


#7

try Lloyd instead of LLoyd


#8

Goku always says that :smile:

All you need is a loop just got and idea from @aealattal

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 new in students:
print new["name"]
print new["homework"]
print new["quizzes"]
print new["tests"]