Python 利用字典设计学生成绩信息系统
结果操作的时候出现问题
说有关遍历的操作的循环有问题,请问是哪出问题了吗》如何解决呢?
while True:
students = {'1001': {'name': "Janis Joplin", 'gender': 'male', 'age': 19, 'score': 598, 'subject1': '高等数学',
'subject2': "珠宝设计", 'score1': "高等数学78", 'score2': "珠宝设计99"},
'1002': {'name': "Kurt Cobain", 'gender': 'female', 'age': 18, 'score': 556, 'subject1': 'C语言程序设计',
'subject2': "艺术鉴赏", 'score1': "C语言程序设计82", 'score2': "艺术鉴赏67"},
'1003': {'name': "Gogo", 'gender': 'female', 'age': 20, 'score': 588, 'subject1': "离散数学",
'subject2': " 数据结构", 'score1': "离散数学78", 'score2': "数据结构99", },
'1004': {'name': "Jimi", 'gender': 'male', 'age': 18, 'score': 568, 'subject1': "Python程序设计",
'subject2': "html基础", 'score1': "Python程序设计89", 'score2': "html基础77"},
"1001 高等数学": {"score": 78},
"1001 珠宝设计": {"score": 99},
"1002 C语言成句设计": {"score": 82},
"1002 艺术鉴赏": {"score": 67},
"1003 离散数学": {"score": 78},
"1003 数据结构": {"score": 99},
"1004 Python程序设计": {"score": 89},
"1004 html基础": {"score": 77},
}
print("1.字典中存储字典")
print("2.输入ID是1001的信息")
print("3.按照输入的ID进行查询")
print("4.字典嵌套的遍历")
print("5.统计男女各有多少人,输入年龄大于18岁的学生的姓名")
print("6.输出成绩最高的学生信息")
print("7.遍历学生所选课程")
print("8.遍历学生各科成绩")
print("9.查找学生指定学科成绩")
print("10.退出系统")
n = int(input("请输入你的操作选项:"))
if n == 1:
students = {'1001': {'name': "Janis Joplin", 'gender': 'male', 'age': 19, 'score': 598, 'subject1': '高等数学',
'subject2': "珠宝设计", 'score1': "高等数学78", 'score2': "珠宝设计99"},
'1002': {'name': "Kurt Cobain", 'gender': 'female', 'age': 18, 'score': 556, 'subject1': 'C语言程序设计',
'subject2': "艺术鉴赏", 'score1': "C语言程序设计82", 'score2': "艺术鉴赏67"},
'1003': {'name': "Gogo", 'gender': 'female', 'age': 20, 'score': 588, 'subject1': "离散数学",
'subject2': " 数据结构", 'score1': "离散数学78", 'score2': "数据结构99",},
'1004': {'name': "Jimi", 'gender': 'male', 'age': 18, 'score': 568, 'subject1': "Python程序设计",
'subject2': "html基础", 'score1': "Python程序设计89", 'score2': "html基础77"},
"1001 高等数学": {"SCORE": 78},
"1001 珠宝设计": {"SCORE": 99},
"1002 C语言成句设计": {"SCORE": 82},
"1002 艺术鉴赏": {"SCORE": 67},
"1003 离散数学": {"SCORE": 78},
"1003 数据结构": {"SCORE": 99},
"1004 Python程序设计": {"SCORE": 89},
"1004 html基础": {"SCORE": 77},
}
print(students)
print(" ------------------------")
elif n == 2:
print(students['1001'])
print(students['1001']['name'])
print("-----------------------")
elif n == 3:
xh = input("please input ID:")
if xh in students:
print(students[xh])
else:
print("not find")
print("--------------------------")
elif n == 4:
for k, v in students.items():
print(k,v['nmae'], v['gender'], v['age'], v['score'])
print("----------------------------------")
elif n == 5:
cnt = {}
xm = []
for k, v in students.items():
cnt[v['gender']] = cnt.get(v['gender'], 0) + 1
if v['age'] > 18:
xm.append(v['name'])
print("female=%d male=%d" % (cnt['female'], cnt['male']))
print(">18", xm)
print("-----------------------------------------")
elif n == 6:
MAX = max(students, key=lambda x: students[x]['score'])
print(MAX)
print(students[MAX])
print("--------------------------------------")
elif n == 7:
for c, d in students.items():
print(c,d['name'],d['subject1'],d['subject2'])
print("----------------------------------")
elif n == 8:
for a, b in students.items():
print(a, b['name'],b['score1'],b['score2'])
elif n==9:
j=input(("请输入所查成绩学生姓名和科目:"))
if j in students:
print(students[j])
else:
print("输入错误!")
break
elif n == 10:
break
else:
print("输入错误!")
print("-----------------------------------------------------------")
print("-----------程序运行结束--------------")