有没有更干净的方法来构造我的打印功能?
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 student["name"]
print student["homework"]
print student["quizzes"]
print student["tests"]
我尝试了以下代码,但出现语法错误:
for student in students:
print student["name", "homework", "quizzes", "tests"]
如果这个问题已经得到解答,我深表歉意,但是我找不到问题。
我将使用第二个for
循环:
for student in students:
for x in ("name", "homework", "quizzes", "tests"):
print student[x]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句