在以下代码中:
grades = {
("DD1", 1) : 45,
("DD1", 2) : 75,
("DD1", 3) : 25,
("DD1", 4) : 65,
("DD2", 1) : 85,
("DD2", 2) : 40,
("DD2", 3) : 70,
("DD2", 4) : 80,
}
def listGrades(dataBase, group):
list_of_score = []
for key, value in dataBase.items():
if key[0] == group:
list_of_score.append(value)
return list_of_score
dataBase = input("Which database?")
group = input("which group?")
print(listGrades(dataBase, group))
调试后,我得到这个:
Which database?grades
which group?DD1
Traceback (most recent call last):
File "C:\Users\DuckyGoh\Desktop\1003\tt3.py", line 51, in <module>
print(listGrades(dataBase, group))
File "C:\Users\DuckyGoh\Desktop\1003\tt3.py", line 43, in listGrades
for key, value in dataBase.items():
AttributeError: 'str' object has no attribute 'items'
有人可以教育我我的错误以及如何解决这个问题。
人到中年有点甜
相关分类