python基础学习第三天下(学生信息管理系统小案例 ps实现登陆逻辑)



#Student类(属性)
class Student:
#初始化属性
      def __init__(self,sid,sname,sage,score):
            self.sid = sid
            self.sname = sname
            self.sage = sage
            self.score = score

#StudentDao类(方法)
class StudentDao:
      #定义空集合,准备装学生对象
      students =set()
      #增加学生

      def saveStudent(self,student):
             self.students.add(student)
      #删除学生
      def deleteStudent(self,sid):
            for student in self.students:
                  if student.sid==sid:
                        self.students.remove(student)
                        break
      #更新学生
      def updateStudent(self,stu):
            for student in self.students:
                  if student.sid==stu.sid:
                        students.remove(student)
                        self.students.add(stu)                       
                        break
      #根据id查询学生
      def queryStudentBySid(self,sid):
            for student in self.students:
                  if student.sid==sid:
                        return student
      #查询全部学生
      def queryAllStudent(self):
            return self.students

class UserInfo:
      def __init__(self,userId,userPwd):
            self.userId=userId
            self.userPwd=userPwd

class UserInfoDao:
      userInfos={UserInfo("admin","admin"),UserInfo("system","system")}

      def checkLogin(self,userInfo):
            for user in self.userInfos:
                  flag=False
                  if (userInfo.userId==user.userId and userInfo.userPwd==user.userPwd):
                        flag=True
                        return flag     
                  else:
                        return False
print("请登录!")
userId=input("请输入账号...")
userPwd=input("请输入密码...")
_userInfo=UserInfo(userId,userPwd)

userInfoDao=UserInfoDao()
if userInfoDao.checkLogin(_userInfo)==True:
      while True:
           
            print("欢 迎 使 用 中 南 大 学 学 生 管 理 系 统")
            print("1.新增学生\n2.修改学生\n3.删除学生\n4.查询所有学生\n5.按学号查询学生\n6.退出系统")
            choice=int(input("请选择..."))
            if(choice==1): 
                  sid=int(input("请输入添加的学生学号..."))
                  sname=input("请输入添加的学生姓名...")
                  sage=int(input("请输入添加的学生年龄..."))
                  score=int(input("请输入添加的学生成绩..."))
                  student=Student(sid,sname,sage,score)
            #调用添加方法
                  studentDao = StudentDao()
                  studentDao.saveStudent(student)
            elif(choice==2):
                 sid=int(input("请输入要修改的学生学号..."))
                 sname=input("请输入要修改的学生姓名...")
                 sage=int(input("请输入要修改的学生年龄..."))
                 score=int(input("请输入要修改的学生成绩..."))
                 student=Student(sid,sname,sage,score)
            #调用修改方法
                 studentDao=StudentDao()
                 studentDao.updateStudent(student)
            elif(choice==3):
                 sid=int(input("请输入要删除的学生学号..."))
            #调用删除方法
                 studentDao=StudentDao()
                 studentDao.deleteStudent(sid)
            elif(choice==4):
            #调用查询所有学生方法 
                 studentDao=StudentDao()
                 students=studentDao.queryAllStudent()
                 print("中南学生信息如下..\n")
                 for student in students:
                      print("学号:%d,姓名:%s,年龄:%d,成绩:%d"%(student.sid,student.sname,student.sage,student.score))
            elif(choice==5):           
                 sid=int(input("请输入要查询的学生学号..."))
            #调用查询学号的方法
                 studentDao=StudentDao()
                 student = studentDao.queryStudentBySid(sid)     
                 print("学号:%d,姓名:%s,年龄:%d,成绩:%d"%(student.sid,student.sname,student.sage,student.score))
            elif(choice==6):
                break
else:
      print("登陆失败!")
                       
                 



你可能感兴趣的:(python基础学习第三天下(学生信息管理系统小案例 ps实现登陆逻辑))