Student achievement management system
This article will achieve a simple management of student scores, the following show the requirements of the experiment: 1, create 4. Py modules, in a package, module named main.py, ui.py, model.
2. (1) The output display interface of the student management system on the console is shown in Figure 1.
(2) Establish the student class in model.py module, which contains the attributes of name, age, score and ID.
(3) Establish the business logic class of student management in bll.py module, that is, realize the functions of adding, displaying, deleting, modifying and ranking scores in this module.
(4) Establish student management display interface in UI.py module.
If name == “main” in main.py module
Tip: This program starts by creating a package
A. Model. Py
Establish a student category
`class Students(object) :
""" a simple expression for a student """ "
def __init__(self,stu_id,stu_name,stu_age,stu_score) :
""" Sets the initial value of the property """
self.stu_name = stu_name # the name
self.stu_id=stu_id# student id
self.stu_age=stu_age# age
self.stu_score=stu_score# scores
def __str__(self) :
return 'Student ID: {} Name: {} Age: {} Result: {}'.format(self.stu_id,self.stu_name,self.stu_age,self.stu_score)`
Copy the code
2. The BLL. Py
`fromGrade management. Modelimport *
class StudentManagerController(object) :
def __init__(self) :
self.stu_list=[]Define a list
def add(self) :
#1. Add student information
flase=0
while flase == 0:
id = int(input("Student number."))
if id>0:
print('Reenter')
else:
flase=1
name=input("Name:")
flase = 0
while flase == 0:
age = int(input("Age."))
if 0 < age:
flase = True
else:
print('Reenter')
flase = 0
while flase == 0:
score = int(input("Performance."))
if 0 < score:
flase = True
else:
print('Reenter')
flase = 0
stu = Students(id,name,age,score)
self.add_stu(stu)
def show(self) :
#2. Display the list of students
if len(self.stu_list) == 0:
print("There are no current student records.")
self.show_stu()
def del_stu1(self) :
#3. Delete student information
stu_id = int(input("Please enter student number (delete):"))
stu_id1=stu_id-1
for stu_id in self.stu_list:
if stu_id in self.stu_list:
self.del_stu(stu_id1)
def revise1(self) :
#4. Modify students
num = int(input("Please enter modify student number :"))
num1=num-1
flase = 0
while flase == 0:
id1 = int(input("Enter new student ID:"))
if 0 < id1:
flase = True
else:
print('Reenter')
name1 = input('Enter new name:')
flase = 0
while flase == 0:
age1 = int(input("Enter new age:"))
if 0 < age1:
flase = True
else:
print('Reenter')
flase = 0
while flase == 0:
score1 = int(input("Enter a new score:"))
if 0 < score1:
flase = True
else:
print('Reenter')
flase = 0
stu1 = Students(id1,name1,age1, score1)
self.stu_list[num1] = stu1
self.show_stu()
def paixv(self) :
Sort: # 5.
self.sort_stu(key=lambda s: s.stu_score, reverse=True) # By score
self.show_stu()
def add_stu(self,stu) :# add
self.stu_list.append(stu)Add variables to the end of the list
#self.stu_dict[stu.stu_id]= STU# nested dictionary in the list
def del_stu(self,stu_id) :# remove
#s=self.stu_dict[stu_id]
self.stu_list.remove(stu_id)Delete student information according to number
def sort_stu(self,key=None,reverse=False) :# sort key=lambda variable: variable [dimension]. The dimensions can be set to suit your needs.
self.stu_list.sort(key=key,reverse=reverse)
def revise_stu(self,stu1) :# modified
a=int(input("Enter the number of digits you want to modify the student."))
self.stu_list[a]=stu1
def show_stu(self) :# show
for s in self.stu_list:# walk through the list
print(s)`
Copy the code
3. The UI. Py
`fromGrade management. BLLimport *
class StudentManagerView(object) :
def __init__(self) :
self.mamager=StudentManagerController()# instantiation
def shixian(self) :
while True:
# # show_menu that demonstrates () call UI. Py
print(The '*' * 20)
print('1) Add student ')
print('2) Show student ')
print('3) Delete student ')
print('4) Modify students')
print('5) In descending order of achievement ')
print('0) Exit program ')
print(The '*' * 20)
key=int(input("Please enter the function :"))
if key in range(0.6) :if key==1:
self.mamager.add()
elif key==2:
self.mamager.show()
elif key==3:
self.mamager.del_stu1()
elif key==4:
self.mamager.revise1()
elif key==5:
self.mamager.paixv()
else:
print("Exit program")
break
else:
print("Input error!") `Copy the code
Four main. Py
`fromGrade management. UIimport*
if __name__=="__main__":
n=StudentManagerView()
n.shixian()`
Copy the code
That’s the simple implementation of the case. You can send a private message if you want.
Original link: www.sdk.cn/details/J5r…
SDK is a neutral communities, there are a variety of front knowledge, has the rich API, developers have a love of learning artificial intelligence, have humor developers take you learn python, there will be the next hot HongMeng, when various elements together, let us together to build professional, fun and imaginative valuable developer community, Help developers realize their self-worth!