• 菜逼的学生信息管理系统


    简单粗暴的贴代码

    
    

    import re
    class Node:
    def __init__(self,data={"num":'00',"name":'星',"tel":'00'}):
    self.data=data
    self.next=None

    
    

    class Linklist:
    def __init__(self):
    node=Node(data={"num":'00',"name":'星',"tel":'00'})
    self.head=node
    self.tail=node
    def display(self):
    node=self.head
    node=node.next
    i=1
    while node is not None:
    print("第"+str(i)+"学生的信息为")
    print("学号为:"+node.data["num"]+" 姓名为:"+node.data["name"]+" 电话为"+node.data["tel"])
    node=node.next
    i=i+1
    def add(self,num,name,tel):
    data={"num":num,"name":name,"tel":tel}
    node=Node(data)
    self.tail.next=node
    self.tail=self.tail.next

    def search(self):
    n=str(input("请输入要查找学生的学号"))
    node=self.head
    node=node.next
    flag=0
    while n==(node.data["num"]):
    flag=1
    print("yeeeeeeeeeeee! 找到了!")
    print("学号为:"+node.data["num"]+"姓名为:"+node.data["name"]+"电话为:"+node.data["tel"])
    break
    else :
    node=node.next
    if flag==0:
    print("查无此人")
    def save(self):
    node=self.head
    node=node.next
    fh=open("students.txt","a+",encoding="utf-8")
    while node is not None:
    fh.writelines(node.data["num"]+" ")
    fh.writelines(node.data["name"]+" ")
    fh.writelines(node.data["tel"]+" ")
    node=node.next
    print("数据已保存于students.txt")
    fh.close()
    def get(self):
    node=self.head
    '''data={"num":'00',"name":'星',"tel":'00'}
    node=Node(data)
    self.tail.next=node
    self.tail=self.tail.next'''
    with open ('students.txt',mode='r+',encoding='utf-8') as f:
    for line in f:
    #print(line)
    text=re.search('^([0-9]+) ([u4e00-u9fa5]+) ([0-9]+)',line.strip())
    data={"num":text.group(1),"name":text.group(2),"tel":text.group(3)}
    node=Node(data)
    self.tail.next=node
    self.tail=self.tail.next
    '''print("学号为"+node.data["num"]+" 姓名为"+node.data["name"]+" 电话为:"+node.data["tel"])
    node.data["num"]=str(text.group(1))#没有创建节点就直接赋值???
    node.data["name"]=str(text.group(2))
    node.data["tel"]=str(text.group(3))
    node=node.next'''

    def modify(self):
    flag2=0
    n=str(input("请输入要修改学生的学号"))
    node=self.head
    node=node.next
    while n==(node.data["num"]):
    flag2=1
    print("该学生信息为:")
    print("学号为"+node.data["num"]+" 姓名为"+node.data["name"]+" 电话为"+node.data["tel"])
    break
    else :
    node1=node
    node=node.next
    if flag2==1:
    m=int(input("请输入要修改学生的哪项形象:学号请按1 姓名请按2 电话请按3"))
    if m==1:
    k=str(input("请输入要修改后学生的学号"))
    node.data["num"]=k
    if m==2:
    k=str(input("请输入要修改后学生的姓名"))
    node.data["name"]=k
    if m==3:
    k=str(input("请输入要修改后学生的电话"))
    node.data["tel"]=k
    print("修改完成")
    elif flag2==0:
    print("查无此人")

    
    


    def delet(self):
    flag1=0
    n=str(input("请输入要删除学生的学号"))
    node=self.head
    node=node.next
    if n==node.data["num"]:
    print("该学生信息为:")
    print("学号为:"+node.data["num"]+"姓名为:"+node.data["name"]+"电话为:"+node.data["tel"])
    m=int(input("确认删除请按1否则请按2"))
    if m==1:
    self.head=self.head.next
    print("删除完毕")
    flag1=1
    if flag1==0:
    while n==(node.data["num"]):
    print("该学生信息为:")
    print("学号为:"+node.data["num"]+"姓名为:"+node.data["name"]+"电话为:"+node.data["tel"])
    break
    else :
    node1=node
    node=node.next
    m=int(input("确认删除请按1否则请按2"))
    if m==1:
    node1.next=node1.next.next
    print("删除完毕")

    
    

    '''class Stu:
    def __init__(self,num,name,tel):
    self.num = num
    self.name = name
    self.tel = tel'''

    
    
    
    
    

    def menu():
    print(" *** batman学生管理系统 ***")
    print('1.添加学生数据 2.删除学生数据')
    print('3.显示学生数据 4.查找学生数据')
    print('5.修改学生数据 6.保存学生数据')
    print('7.读取学生数据 0.退出系统')

    
    


    def main():

    
    

    while 1:
    menu()
    select =int(input(' 请输入选项:'))
    if select==1:
    n=int(input("请输入要添加的学生个数"))
    i=0
    while(i<n):
    num=input("学号")
    name=input("姓名"+"tip姓名必须为中文")
    tel=input("电话")
    list1.add(num,name,tel)
    i=i+1
    elif select==2:
    list1.delet()
    elif select==3:
    list1.display()
    elif select==4:
    list1.search()
    elif select==5:
    list1.modify()
    elif select==6:
    list1.save()
    elif select==7:
    list1.get()
    elif select==0:
    break
    else:
    print('输入的选项有误,请重新输入')

    
    

    list1 = Linklist()
    print("如果你是第一次使用则不需要读取数据,当然你也可以稍后在读")
    s1=int(input("请问是否要先从数据库中读取数据 1代表读 2代表不读"))
    if s1==1:
    list1.get()
    else :
    pass
    main()

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    



    
    

     一个不会因为关闭程序就清除数据的蒟蒻程序

    当然还有很多很多不足

    如果你够坚强够勇敢,你就能驾驭他们
  • 相关阅读:
    Linux使用手册
    Oracle&SQL使用记录
    docker的使用
    springboot与mybatis
    JavaScript与TypeScript总结
    React总结
    React与jsplumb
    DB2入门
    吾尝终日而思矣——2019.02.17
    吾尝终日而思矣——2019.02.12
  • 原文地址:https://www.cnblogs.com/liuzhaojun/p/10962202.html
Copyright © 2020-2023  润新知