python学生管理系统(类)

import os
class Student():
def init(self,name,qq,phone):
self.name=name
self.qq=qq
self.phone=phone
def str(self):
return self.name+"\t"+str(self.qq)+"\t"+str(self.phone)

class StudentManager:

students=[];

@classmethod
def addStudent(cls):
    name=input("please input name:")
    qq=int(input("please input qq:"))
    phone=int(input("please input phone:"))
    student=Student(name,qq,phone)
    cls.students.append(student);
    
@classmethod
def display(cls):
    print("Name\tQQ\tPhone")
    for student in cls.students:
        print(student)
@classmethod
def delete(cls):
    name=input("please input the name what you want delete:")
    for student in cls.students:
        if student.name==name:
            cls.students.remove(student)
            break
    else:
        print("there is not have the sutdent")
@classmethod
def update(cls):
    name=input("please input the name what you want update")
    for student in cls.students:
        if student.name==name:
            index=cls.students.index(student)
            cls.students[index].name=input("Please input the new name:")
            cls.students[index].qq=int(input("Please input your new qq:"))
            cls.students[index].phone=int(input("Please input your new phone:"))
            return
@classmethod
def read(cls):
    a=os.path.exists('student.dat')
    if a==True:
        with open("student.dat","r") as f:
            line=f.readline()
            while(line!=''):
                lines=line.rstrip().split(",")
                student=Student(lines[0],lines[1],lines[2])
                cls.students.append(student)
                line=f.readline()
@classmethod
def write(cls):
    with open("student.dat", "w") as f:
        for student in cls.students:
            f.write(student.name+","+str(student.qq)+","+str(student.phone)+"\n")

@staticmethod
def menu():
    print("*"*30)
    print("1:add")
    print("2:display")
    print("3:delete")
    print("4:update")
    print("5:exit")
    print("*"*30)
    


    
@staticmethod
def run():
    StudentManager.read()
    while(True):
        StudentManager.menu()
        operator=input("please input your choice:")
        if operator=="1":
            StudentManager.addStudent()
        if operator=="2":
            StudentManager.display()
        if operator=="3":
            StudentManager.delete()
        if operator=="4":
            StudentManager.update()
        if operator=="5":
            StudentManager.write()
            break

if name==“main”:
StudentManager.run()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值