我写的代码就在下面,我的问题就在下面。
student= {}
for i in range(5):
name = input("Add students name: ")
grade = input("Add students grade: ")
student[name] = grade
print(student)
我的问题会更容易向您展示,我希望输出如下所示,但我似乎无法得到最后两行
"输入名称:Sue
输入等级:90
输入名称:Bob
输入等级:60
输入名称:Kim
输入等级:55
输入名称:Jim
输入等级:100
输入姓名:Sarah
输入等级:95
{‘Jim’:100.0,‘Kim’:55.0,‘Sue’:90.0,‘Sarah’:95.0,‘Bob’:60.0}
键入要在字典中查找的名称:Jim
等级为:100.0〃;
如果你能帮我得到上面列出的东西,那将非常有帮助。谢谢
检查下面的代码中是否存在此问题。
student= {}
for i in range(3):
name = input("Add students name: ")
grade = input("Add students grade: ")
student[name] = grade
lookup_name = input("Type a name to lookup in the dictionary: ")
try:
lookup_grade = student[lookup_name]
print(lookup_grade)
except:
print('name not in list')
输出:
Add students name: A
Add students grade: 50
Add students name: B
Add students grade: 60
Add students name: C
Add students grade: 70
Type a name to lookup in the dictionary: B
60
如果有帮助,请接受答案。