Python implements the student information management system, python
After the Python Implementation of the simple address book in the previous blog, I want to write a complex student information management system.
1. Entry Management of student information;
2. Course Selection operations for students;
3. query the Course selections of students;
The sqlite3 module is still used this time. Although it looks quite simple, I have also stepped on a lot of pitfalls. After all, some details need to be refined at the beginning!
Okay, I don't want to talk about it. I just need to go to the code and welcome friends who are interested to discuss it in private ~~~
#-*-Coding: UTF-8-*-import sqlite3 # Open the local database to store user information. conn = export cute (''' create table StudentTable (id integer primary key autoincrement, stuId integer not null, name text not null, class int not null );''') print "Table created successfully" created under this database, the course information TABLE conn.exe cute ('''create Table CourseTable (id integer primary key autoincrement, CourseId INT NOT NUL L, Name text not null, Teacher text not null, Classroom text not null, StartTime CHAR (11) not null, EndTime CHAR (11) not null );''') print "Table created successfully" comment cute (''' create table XuankeTable (id integer primary key autoincrement, StuId int not null, CourseId int not null, StudentNAME text null, studenCourse text null); ''') print "Table created successfully"; # create the above three tables After running the program again, you need to comment out the three table creation codes. Otherwise, the system will prompt that the table already exists. That is, you only need to create a table once. Def insert_stu (): # Enter student information conn = sqlite3.connect ('student. db ') stu_id = input ("Enter the student ID:") cursor = conn.exe cute ("SELECT StuId from StudentTable where StuId =' % s';" % stu_id) conn. commit () for row in cursor: if stu_id = row [0]: print "sorry, this student ID already exists. Please enter" break else: stu_name = raw_input ("Enter the Student NAME:") stu_class = input ("Enter the student CLASS:") sql1 = "insert into StudentTable (StuId, NAME, CLASS) "sql1 + =" VALUES (% d, '% S', % d); "% (stu_id, stu_name, stu_class) conn.exe cute (sql1) conn. commit () print" congratulations, student input successful! "Def xuanke (): # Students Course Selection stu_id = input ('Enter the student ID to be selected: ') sql2 =" select StuId from StudentTable where StuId = % d; "% (stu_id) cursor1 = conn.exe cute (sql2) for row in cursor1: if stu_id = row [0]: sql3 =" select CourseId, Name, Teacher, Classroom, StartTime, endTime from CourseTable "cursor2 = conn.exe cute (sql3) for row in cursor2: print" CourseId = ", row [0] print" Name = ", row [1] print "Teacher =", row [2] Print "Classroom =", row [3] print "StartTime =", row [4] print "EndTime =", row [5], "\ n" cou_id = input ("Enter the course number to be selected:") SQL = "select StuId from XuankeTable where CourseId = % d;" % (cou_id) cursor3 = conn.exe cute (SQL) for row in cursor3: if stu_id = row [0]: print "this course has been selected. Please enter the course again! "Else: sql3 =" insert into XuankeTable (StuId, CourseId) values (% d, % d) "% (stu_id, cou_id) cursor4 = conn.exe cute (sql3) conn. commit () print "congratulations, Course Selection successful! "Break else: print" sorry, no student ID "def stu_id_search (): # query student information by student ID conn = sqlite3.connect ('student. db ') search_stu_id = input ("Enter the student ID to query:") sql4 = "SELECT StuId from StudentTable where StuId = % d;" % (search_stu_id) cursor1 = conn.exe cute (sql4) conn. commit () for row in cursor1: if search_stu_id = row [0]: sql10 = "select ID, StuId, NAME, CLASS from StudentTable where StuId = % d; "% (search _ Stu_id) cursor2 = conn.exe cute (sql10) conn. commit () for row in cursor2: print "the student information you want to query is:" print "ID =", row [0] print "StuId = ", row [1] print "NAME =", row [2] print "CLASS =", row [3], "\ n" break else: print "sorry, no student information! "Def stu_id_cou (): # query the students selected by student ID stu_id = input (" Enter the student ID to query :") sql5 = "select StuId from StudentTable where StuId = % d;" % (stu_id) cursor = conn.exe cute (sql5) for row in cursor: if stu_id = row [0]: sql6 = "select CourseId from XuankeTable where StuId = % d;" % (stu_id) cursor = conn.exe cute (sql6) conn. commit () for row in cursor: print "this student selected course number:" print row print break else: print "sorry, no such student Course Selection information! "Def cou_id_search (): # query course information by course number cou_id = input (" Enter the course number to query: ") sql7 =" select CourseId, Name, Teacher, Classroom, startTime, EndTime from CourseTable "sql7 + =" where CourseId = % d; "% (cou_id) cursor1 = conn.exe cute (sql7) conn. commit () for row in cursor1: print "the course information you want to query is:" print "CourseId =", row [0] print "Name = ", row [1] print "Teacher =", row [2] print "Classroom =", row [3] print "StartTime = ", Row [4] print "EndTime =", row [5], "\ n" break else: print "sorry, no course information! "Def cou_id_stu (): # select the student list cou_id = input for this course according to the course number query ('Enter the course number :') sql8 = "select CourseId from XuankeTable where CourseId = % d;" % (cou_id) cursor1 = conn.exe cute (sql8) for row in cursor1: if cou_id = row [0]: sql9 = "select StuId from XuankeTable where CourseId = % d;" % (cou_id) cursor2 = conn.exe cute (sql9) conn. commit () for row in cursor2: print "students who select this course are:" print row, "\ n" break else: print "s Orry, no course information! "Def menu (): print '1. enter the Student Information System (Student Information Input) 'print' 2. go to the Student Course Selection System (student course selection operation) 'print' 3. go to the Student Course Selection Information System (student information query and Course Selection query) 'print' 4. exit the program 'def student (): print '1. enter the student information 'print' 2. return to the main menu 'print' 3. exit the program 'def Course (): print '1. start course selection 'print' 2. return to the main menu 'print' 3. exit the program 'def information (): print '1. query student information by student ID 'print' 2. view the student course list 'print' by student ID 3. view the course information 'print' by course number 4. view the "print" List of course students by course number 5. return to the main menu 'print' 6. exit program 'while True: menu () print x = Raw_input ('enter your selection menu number: ') if x = '1': # enter the student Information System student () stu = raw_input ('You have entered the student input system. Enter the selection menu again:') if stu = '1': insert_stu () continue if stu = '2 ': menu () continue if stu = '3': print "Thank you! "Exit () continue else: print" the input option does not exist. Please enter it again! "Continue if x = '2': # enter the Course selection Information System Course () cou = raw_input ('you have entered the Course selection system. Please enter the selection menu again :') if cou = '1': xuanke () continue if cou = '2': menu () continue if cou = '3': print "Thank you! "Exit () continue else: print" the input option does not exist. Please enter it again! "Continue if x = '3': # enter the student course selection information table information () inf = raw_input ('you have entered the student course selection information system. Please enter the selection menu again :') if inf = '1': stu_id_search () continue if inf = '2': stu_id_cou () continue if inf = '3': cou_id_search () continue if inf = '4': cou_id_stu () continue if inf = '5': menu () continue if inf = '6': print "Thank you! "Exit () continue else: print" the input option does not exist. Please enter it again! "Continue if x = '4': print" Thank you! "Exit () else: print" the input option does not exist. Please enter it again! "Continue
For more information, see management system development.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.