标题:本人小白,求大佬解答程序为什么会报错
只看楼主
xumingji
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-7-21
结帖率:0
已结贴  问题点数:20 回复次数:1 
本人小白,求大佬解答程序为什么会报错

print("欢迎来到学生管理系统!")

students=[]
def add_student():
    print("请输入学生信息")
    num=input("请输入学生学号:")
    name=input("请输入学生姓名:")
    age=input("请输入学生年龄;")
    grade=input("请输入学生的班级:")
    student={"num":num,"name":name,"age":age,"grade":grade}
    students.append(student)
    print("添加成功!")
def list_student():
    print("以下为所有学生信息")
    for i in students:
        num=i['num']
        name=i['name']
        age=i['age']
        grade=i['grade']
        print("学号:%s,姓名:%s,年龄:%s,班级;%s"%(num,name,age,grade))
def find_student():
    num=input("请输入学号:")
    for i in students:
        if i[num]==num:
            num=i['num']
            name=i['name']
            age=i['age']
            grade=i['grade']
            print("学号:%s,姓名:%s,年龄:%s,班级;%s"%(num,name,age,grade))
        else:
            print("输入错误请重新输入")
            continue
def delete_student():
    num=input("请输入你要删除学生的学号:")
    for i in students:
        if i[num]==num:
            num=i['num']
            name=i['name']
            age=i['age']
            grade=i['grade']
            print("学号:%s,姓名:%s,年龄:%s,班级;%s"%(num,name,age,grade))
            a=input("是否要删除")
            if a=="是":
                students.pop('num','name','age','grade')
            else:
                break
        else:
            print("输入错误,请重新输入")
            continue
def main():
    while True:
        print("="*20)
        print("1.新增学生信息")
        print("2.列出所有学生信息")
        print("3.查找学生信息")
        print("4.删除学生信息")
        print("="*20)
        number=input("请输入你要操作的序号:")
        if not number.isdigit() or number not in ['1','2','3','4']:
            print("序号输入不正确!")
            continue
        else:
            if number=='1':
                add_student()
            elif number=='2':
                list_student()
            elif number=='3':
                find_student()
            else:
                delete_student()

if __name__=='__main__':
    main()
搜索更多相关主题的帖子: print 输入 num name age 
2019-07-21 22:55
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:20 
if i[num]==num:  是不是得这样写啊  if i['num']==num:

DO IT YOURSELF !
2019-07-22 10:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-495977-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014668 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved