美文网首页
学生管理系统2.0

学生管理系统2.0

作者: 葡萄柚子茶 | 来源:发表于2018-09-02 22:14 被阅读0次
    #显示主菜单
    def show_menu():
       print('欢迎进入千峰学生管理系统'.center(20, '='))
       print('1.添加学生')
       print('2.删除学生')
       print('3.修改信息')
       print('4.查找信息')
       print('q.退出')
       print('=' * 20)
    
    #1.添加学生
    def add_student():
       student_list = []
       while True:
           with open('./student.txt','r',encoding='utf-8') as f:
               content = f.read()
    
           name1 = input('请输入学生的姓名:')
           age1 = input('请输入学生的年龄:')
           phone1 = input('请输入学生的电话:')
           dict1 = {'name': name1,  'age': age1, 'phone': phone1}
           student_list.append(dict1)
           f = open('./student.txt', 'w', encoding='utf-8')
           f.write(str(dict1)+'\n')
           f.close()
           print('=' * 20)
           print('添加成功!!!')
           print('1.继续添加')
           print('2.返回上层')
           print('=' * 20)
           x1 = int(input('请选择:'))
           if x1 == 1:
               continue
           else:
               show_menu()
               x2 = int(input('请选择:'))
               if x2 == 1:
                   add_student()
               elif x2 == 2:
                   del_student()
               elif x2 == 3:
                   change_student()
               elif x2 == 4:
                   find_student()
               else:
                   print('欢迎下次使用')
                   break
    #2.删除学生
    def del_student():
       while True:
           name2 = input('请输入要删除的学生姓名:')
           with open('./student.txt','r',encoding='utf-8') as f:
               student_list = eval(f.read())
           print(student_list)
           for student in student_list:
               if student['name'] == name2:
                   student_list.remove(student)
               print(student_list)
               with open('./student.txt','r',encoding='utf-8') as f:
                   content = f.write(str(student_list))
               print('删除成功')
               print('=' * 20)
               print('1.继续删除')
               print('2.退出')
               print('=' * 20)
               x1 = int(input('请选择:'))
               if x1 == 1:
                   continue
               else:
                   show_menu()
                   x2 = int(input('请选择:'))
                   if x2 == 1:
                       add_student()
                   elif x2 == 2:
                       del_student()
                   elif x2 == 3:
                       change_student()
                   elif x2 == 4:
                       find_student()
                   else:
                       print('欢迎下次使用')
                       break
    #3.修改信息
    def change_student():
       while True:
           with open('./student.txt','r',encoding='utf-8') as f:
               student_list = eval(f.read())
           print(student_list)
           name3 = input('请输入要修改的姓名:')
           for student in student_list:
               if name3 == student['name']:
                   print('=' * 20)
                   print(student)
                   print('=' * 20)
                   print('1.修改年龄')
                   print('2.修改电话')
                   x3 = input('请选择:')
                   if x3 == 1:
                       age2 = input('请输入修改后的年龄:')
                       student['age']= age2
                       print('修改成功')
                   else:
                       tel2 = input('请输入修改后的电话')
                       student['tel'] = tel2
                       print('修改成功')
                   with open('./student.txt', 'r',encoding='utf-8') as f:
                       content = f.write(str(student_list))
    
           print('1.继续修改')
           print('2.退出')
           x1 = int(input('请选择:'))
           if x1 == 1:
               continue
           else:
               show_menu()
               x2 = int(input('请选择:'))
               if x2 == 1:
                   add_student()
               elif x2 == 2:
                   del_student()
               elif x2 == 3:
                   change_student()
               elif x2 == 4:
                   find_student()
               else:
                   print('欢迎下次使用')
                   break
    #4.查找信息
    def find_student():
       while True:
           with open('./student.txt','r',encoding='utf-8') as f:
               student_list = eval(f.read())
           print('1.按姓名查找')
           print('1.按年龄查找')
           print('1.按电话查找')
           print('=' * 20)
           x4 = int(input('请选择:'))
           print('=' * 20)
           if x4 == 1:
               name4 = input('请输入要查找的学生姓名:')
               for student in student_list:
                   if name4 == student['name']:
                       print(student)
                       print('=' * 20)
               print('1.继续查找')
               print('2.退出')
               print('=' * 20)
               x4 = int(input('请选择:'))
               if x4 == 1:
                   continue
               else:
                   show_menu()
                   x2 = int(input('请选择:'))
                   if x2 == 1:
                       add_student()
                   elif x2 == 2:
                       del_student()
                   elif x2 == 3:
                       change_student()
                   elif x2 == 4:
                       find_student()
                   else:
                       print('欢迎下次使用')
                       break
           elif x4 == 2:
               age4 = input('请输入要查找的学生年龄:')
               for student in student_list:
                   if student['age'] == age4:
                       print(student)
                       print('=' * 20)
               print('1.继续查找')
               print('2.退出')
               print('=' * 20)
               x4 = int(input('请选择:'))
               if x4 == 1:
                   continue
               else:
                   show_menu()
                   x2 = int(input('请选择:'))
                   if x2 == 1:
                       add_student()
                   elif x2 == 2:
                       del_student()
                   elif x2 == 3:
                       change_student()
                   elif x2 == 4:
                       find_student()
                   else:
                       print('欢迎下次使用')
                       break
           elif x4 == 3:
               tel4 = input('请输入查找的学生电话:')
               for student in student_list:
                   if student['tel'] == tel4:
                       print(student)
                       print('=' * 20)
               print('1.继续查找')
               print('2.退出')
               print('=' * 20)
               x4 = int(input('请选择:'))
               if x4 == 1:
                   continue
               else:
                   show_menu()
                   x2 = int(input('请选择:'))
                   if x2 == 1:
                       add_student()
                   elif x2 == 2:
                       del_student()
                   elif x2 == 3:
                       change_student()
                   elif x2 == 4:
                       find_student()
                   else:
                       print('欢迎下次使用')
                       break
    #运行
    while True:
       show_menu()
       number1 = int(input('请选择:'))
       if number1 == 1:
           add_student()
       elif number1 == 2:
           del_student()
       elif number1 == 3:
           change_student()
       elif number1 == 4:
           find_student()
       elif str(number1) == 'q':
           print('退出系统')
           break
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:学生管理系统2.0

          本文链接:https://www.haomeiwen.com/subject/bzrvwftx.html