Exercise 1.4: For the Record


#1



https://www.codecademy.com/fr/courses/python-beginner-fr-FR-wdjot/0/4?curriculum_id=5370f030fed2a866a2000001


Hello.
My code doesn't work and i think it's a problem of Indentation but i can't resolve it.

lloyd = {
    "noms": "Lloyd",
    "devoirs": [90.0, 97.0, 75.0, 92.0],
    "quiz": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
alice = {
    "noms": "Alice",
    "devoirs": [100.0, 92.0, 98.0, 100.0],
    "quiz": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
tyler = {
    "noms": "Tyler",
    "devoirs": [0.0, 87.0, 75.0, 22.0],
    "quiz": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}

etudiants = ["lloyd", "alice", "tyler"]
for n in etudiants:
    print n ["noms"]
    print n ["devoirs"]
    print n ["quiz"]
    print n ["tests"]

**Oups, merci de réessayer. Votre code semble incorrect - il engendre une erreur "string indices must be integers, not str". N'hésitez pas à revenir aux exercices précédents si vous avez besoin de vous rappeler la syntaxe !** 

Console message :
Traceback (most recent call last):
  File "python", line 22, in <module>
TypeError: string indices must be integers, not str

**

**## Who said Python was fun to use ?**

**


#2

Hello @snakefinger33gmail.c,

Your etudiants list is the problem. Instead of putting the string names of the students, put the variable name that contains the dictionaries containing the students' information.

Change

etudiants = ["student"]

to

etudiants = [student]

and see if it works. If this doesn't fix it, reply to me, and I'll be happy to help :smile:!


#3

Hi,
i've just done it but it's always the same error message :

Traceback (most recent call last):
File "python", line 22, in
TypeError: string indices must be integers, not str

But thank you.


#4

etudiants = [lloyd, alice, tyler]
for etudiant in etudiants:
print etudiant["noms"]
print etudiant["devoirs"]
print etudiant["quiz"]
print etudiant["tests"]

Thanks a lot. Now it works.:sunglasses:


#5

No problems @snakefinger33gmail.c,

if you feel satisfied with my response, then put my answer as the solution so that other people know that this topic is closed. Keep coding hard :laughing:!


#7

https://www.codecademy.com/courses/python-beginner-en-qzsCL/0/4?curriculum_id=4f89dab3d788890003000096

Everything is good, but it's saying "Lloyd" isn't printed.
Help me. @bartholomewallen


#8

Hello @hemantkagh,

Can you please post your code? Thanks!


#9

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 student in students:
print "Name: %s" %student['name']
print "Homework: %s" %student['homework']
print "Quizzes: %s" %student['quizzes']
print "Tests: %s" %student['tests']
print

Here it is @bartholomewallen.


#10

In your for loop, try just printing the name, homework, quizzes and tests of the student. Don't put placeholders like "Name: %s" %student["name"] just put print student["name"]. That should fix your code up.


Explanation

Your code wasn't working because of the exercises SCT, or the Submission Correctness Test. It checks whether you have printed all the properties of the student dictionaries, and your detailed print statements were probably screwing it up...

Hope this fixes your problem...


#11

Thanks @bartholomewallen. It's working now, but the code, which I wrote, should also be accepted because it's printing all the required info. and even more than that. :wink:
Btw Thanks buddy :slight_smile:


#12

You're welcome, @hemantkagh. Keep coding hard :laughing:!


#13

none of this is working for me...

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 student in students:
    print "Name: %s" %student['name']
print "Homework: %s" %student['homework']
print "Quizzes: %s" %student['quizzes']
print "Tests: %s" %student['tests']
print student["name"].

#14

  File "python", line 31
    print student["name"].
                         ^
SyntaxError: invalid syntax

This is what it says