我需要python文件的帮助才能正确打印出成绩簿。我已经把它打印出来,但它并没有完全按照我的需要去做。打印结果如下所示,
ET_EXEC
理想情况下,我希望在每个名称/等级的新行上打印彼此相邻的名称和等级。像这样:
{'Fred': '99', 'Fred2': '99', ...}
我必须使用列表/字典并需要while循环
这是迄今为止我尝试过的最佳解决方案:
"Name: Fred | Grade: 99"
答案 0 :(得分:0)
for student,grade in student_grades.iteritems():
print "Name:%s, Grade:%s"%(student,grade)
答案 1 :(得分:0)
这是将来可能需要它的任何人的最终工作代码!感谢所有帮助过的人!
student_grades = {}
entries = input('Would you like to enter a students name and grade? (Y/N): ')
entries = entries.lower()
while entries == "y":
name = input('Enter a students name: ')
grade = input('Enter the student\'s grade: ')
#Put in dictionary
student_grades[name] = grade
#Print
print(student_grades)
entries = input('Would you like to enter a students name and grade? (Y/N): ')
entries = entries.lower()
else:
names = list(student_grades.keys())
grades = list(student_grades.values())
print()
print(' Grade Book ')
print('--------------------')
print()
for name in student_grades:
print("Name: "+name+" "+"Grade: "+student_grades[name])