Adam____ 2022-05-25 16:46 采纳率: 81%
浏览 55
已结题

Python 利用字典设计学生成绩信息系统 能帮忙看一下是哪出问题了吗

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("-----------程序运行结束--------------")
  • 写回答

2条回答 默认 最新

  • 二九筒 2022-05-25 17:18
    关注

    问题出在这儿,因为你这些for循环出来的只有前面几个是字典,后面的是字符串,那肯定会有问题的

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月2日
  • 已采纳回答 5月25日
  • 创建了问题 5月25日

悬赏问题

  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。