Python implements the Student Achievement Management System, python

Source: Internet
Author: User

Python implements the Student Achievement Management System, python

This article provides examples of how to use Python to implement the Student Achievement Management System for your reference. The details are as follows:

Basic functions:

Enter and store student information: Enter the student's student ID, name, and score, and then save the data in the student file.

Print all the student information: You can print all the information on the screen through a print function.

Modify student information: this function first queries whether the student exists. If the student exists, it modifies the student information. If the student does not exist, it returns to the main interface.

Delete student information: this function is used to delete students. If a student exists, it can be found and deleted.

Sort by student scores: This function is used to sort student information by student scores.

Find student information: this function is used to enter the student ID to search for the student information. If the student ID exists, the student information is output. If the student ID does not exist, the system prompts that the student ID does not exist.

Initialization

The system implements the initialization function before it starts to use. Check whether the students.txt file contains student information. If so, read the file content for subsequent operations. If not, initialize an empty list, used to save user input. All the subsequent data in the program will be saved in this list, which is equivalent to a data buffer.

The first step is to open the file and read the content in the file. Because the content saved in the file is separated by spaces, each student occupies one row of information, first, read all the content. First, split the content according to the line feed to get the information of each person. Then, separate the information of each person with spaces to obtain the details of each person, including the user's name, student ID, score.

Def Init (stulist): # initialize the function print "to initialize ...... "file_object = open('students.txt ', 'R') for line in file_object: stu = Student () line = line. strip ("\ n") s = line. split ("") stu. ID = s [0] stu. name = s [1] stu. score = s [2] stulist. append (stu) print "initialization successful! "

Score sorting implementation

This part of the code is sorted by the student scores. in implementation, the first step is to put the scores of all people in a list and then sort them by insertion, sort the student information addresses saved in StuList by score size

Def Sort (stulist): # Sort by student scores Stu = [] sum_count = [] for li in stulist: temp = [] temp. append (li. ID) temp. append (li. name) temp. append (int (li. score1) temp. append (int (li. score2) temp. append (int (li. score3) temp. append (int (li. sum) sum_count.append (int (li. sum) Stu. append (temp) # print sum_count # print Stu; # print stulist insertSort (sum_count, stulist) # print stulist; display (stulist) def insertSort (a, stulist ): for I in range (len (a)-1): # print a, I for j in range (I + 1, len ()): if a [I] <a [j]: temp = stulist [I] stulist [I] = stulist [j] stulist [j] = temp

The interface is as follows:

Source code:

#-*-Coding: UTF-8-*-import osimport reimport numpy as npclass Student: # define a Student class def _ init _ (self): self. name = ''self. ID = ''self. score1 = 0 self. score2 = 0 self. score1 = 0 self. sum = 0def searchByID (stulist, ID): # search by student ID to see if student ID already exists for item in stulist: if item. ID = ID: return Truedef Add (stulist, stu): # Add a student information if searchByID (stulist, stu. ID) = True: print "student ID already exists! "Return False stulist. append (stu) print stu. name, stu. ID, stu. score1, stu. score2, stu. score3, stu. sum; print "do you want to save student information? "NChoose = raw_input (" Choose Y/N ") if nChoose = 'y' or nChoose = 'y': file_object = open (" students.txt "," ") file_object.write (stu. ID) file_object.write ("") file_object.write (stu. name) file_object.write ("") file_object.write (str (stu. score1) file_object.write ("") file_object.write (str (stu. score2) file_object.write ("") file_object.write (str (stu. score3) file_object.write ("") file_object.wr Ite (str (stu. sum) file_object.write ("\ n") file_object.close () print u "saved successfully! "Def Search (stulist, ID): # Search for a student information print u" student ID name Chinese Mathematics English total score "count = 0 for item in stulist: if item. ID = ID: print item. ID, '\ t', item. name, '\ t', item. score1, '\ t', item. score2, '\ t', item. score3, '\ t', item. sum break count = 0 if count = len (stulist): print "no student ID for this student! "Def Del (stulist, ID): # delete a student information count = 0 for item in stulist: if item. ID = ID: stulist. remove (item) print "deleted successfully! "Break count + = 1 # if count = len (stulist): # print" no student ID for this student! "File_object = open (" students.txt "," w ") for stu in stulist: print stu. ID, stu. name, stu. score1, stu. score2, stu. score3, stu. sum file_object.write (stu. ID) file_object.write ("") file_object.write (stu. name) file_object.write ("") file_object.write (str (stu. score1) file_object.write ("") file_object.write (str (stu. score2) file_object.write ("") file_object.write (str (stu. score3) file_object.write ("") File_object.write (str (stu. sum) file_object.write ("\ n") file_object.close () # print "saved successfully! "File_object.close () def Change (stulist, ID): count = 0 for item in stulist: if item. ID = ID: stulist. remove (item) file_object = open ("students.txt", "w") for stu in stulist: # print li. ID, li. name, li. score file_object.write (stu. ID) file_object.write ("") file_object.write (stu. name) file_object.write ("") file_object.write (str (stu. score1) file_object.write ("") file_object.write (str (stu. score2 )) File_object.write ("") file_object.write (str (stu. score3) file_object.write ("") file_object.write (str (stu. sum) file_object.write ("\ n") # print "saved successfully! "File_object.close () stu = Student () stu. name = raw_input ("Enter the Student name") while True: stu. ID = raw_input ("Enter student ID") p = re. compile ('^ [0-9] {3} $') if p. match (stu. ID): break else: print "An error occurred! "While True: stu. score1 = int (raw_input ("Enter the student's Chinese score") if stu. score1 <= 100 and stu. score1> 0: break else: print "The Student Score entered is incorrect! "While True: stu. score2 = int (raw_input ("Enter the student's mathematical score") if stu. score2 <= 100 and stu. score2> 0: break else: print "The Student Score entered is incorrect! "While True: stu. score3 = int (raw_input ("Enter your English score") if stu. score3 <= 100 and stu. score3> 0: break else: print "The Student Score entered is incorrect! "Stu. sum = stu. score1 + stu. score2 + stu. score3 Add (stulist, stu) def display (stulist): # display all student information print u "student ID name Chinese Mathematics English total score" for item in stulist: print item. ID, '\ t', item. name, '\ t', item. score1, '\ t', item. score2, '\ t', item. score3, '\ t', item. sumdef Sort (stulist): # Sort by student scores Stu = [] sum_count = [] for li in stulist: temp = [] temp. append (li. ID) temp. append (li. name) temp. append (int (li. score1) temp. app End (int (li. score2) temp. append (int (li. score3) temp. append (int (li. sum) sum_count.append (int (li. sum) Stu. append (temp) # print sum_count # print Stu; # print stulist insertSort (sum_count, stulist) # print stulist; display (stulist) def insertSort (a, stulist ): for I in range (len (a)-1): # print a, I for j in range (I + 1, len ()): if a [I] <a [j]: temp = stulist [I] stulist [I] = stulist [j] stulist [j] = temp # retur N a def Init (stulist): # initialize the function print "to initialize ...... "file_object = open('students.txt ', 'R') for line in file_object: stu = Student () line = line. strip ("\ n") s = line. split ("") stu. ID = s [0] stu. name = s [1] stu. score1 = s [2] stu. score2 = s [3] stu. score3 = s [4] stu. sum = s [5] stulist. append (stu) file_object.close () print "initialization successful! "Main () def main (): # main function the program's entry function while True: print "********************" print u "-------- menu ---------" print u "add student information -------- 1" print u "find student information -------- 2" print u "delete student information -------- 3" print u "Modify student information -------- 4" print u "All Student Information -------- 5" print u "follow score sorting -------- 6 "print u" Exit program ------------ 0 "print" ********************* "nChoose = raw_input ("Enter your options: ") if nChoose =" 1 ": stu = Student () stu. name = raw_input (" Enter the Student name ") while True: stu. ID = raw_input ("Enter student ID") p = re. compile ('^ [0-9] {3} $') if p. match (stu. ID): break else: print "An error occurred! "While True: stu. score1 = int (raw_input ("Enter the student's Chinese score") if stu. score1 <= 100 and stu. score1> 0: break else: print "The Student Score entered is incorrect! "While True: stu. score2 = int (raw_input ("Enter the student's mathematical score") if stu. score2 <= 100 and stu. score2> 0: break else: print "The Student Score entered is incorrect! "While True: stu. score3 = int (raw_input ("Enter your English score") if stu. score3 <= 100 and stu. score3> 0: break else: print "The Student Score entered is incorrect! "Stu. sum = stu. score1 + stu. score2 + stu. score3 Add (stulist, stu) if nChoose = '2': ID = raw_input ("Enter the student ID") Search (stulist, ID) if nChoose = '3': ID = raw_input ("Enter the student ID") Del (stulist, ID) if nChoose = '4 ': ID = raw_input ("Enter student ID") Change (stulist, ID) if nChoose = '5': display (stulist) if nChoose = '6 ': sort (stulist) if nChoose = '0': breakif _ name _ = '_ main _': stulist = [] Init (stulist)

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.