Hello everyone, today I am sharing with you a student registry management system implemented in Python:
The body of the code consists of five functions:
1.add_stu() adds
2.del_stu() delete
3. print_stu()print
4. exit_stu() exit
() Main function
1.add_stu()
What this function does: stores the input values into the dictionary newstu, and stores the dictionary into the list stu.
def add_stu(): newstu = { 'num':int(input("Please enter your school number:"'')), 'name':input("Please enter your name:"''), 'sex':input("Please enter gender:"'') } (newstu) The #stu is a list of definitions, which can be found in the full code below return system()
2.del_stu()
The function of this paragraph: according to the input school number, find out whether the dictionary key value in the list is deposited, if it is deposited, the dictionary will be deleted from the list.
def del_stu(): delstus = int(input("Please enter the student's student number to be deleted:")) k = 0 # Loop incrementing variable to determine the position in the list of dictionaries to be deleted for temp in stu: k+=1 if delstus in range(temp['num'],temp['num']-1,-1): #The temp variable here is the equivalent of a dictionary in a list, and is used in the range function (start, stop, step) to find out if the keys match. print("The student number has been found.") break del stu[( k - 1 )]# Delete dictionaries from the list print("Deleted successfully.") return system()
3.print_stu()
What this function does: iterates over the dictionary in the list as values.
def print_stu(): i = 1 j = 0 k = 1 print("=================================") print("The student information is as follows:") print("=================================") print("Serial No. \t School No. \t Name \t Sex") for s in stu:# Iterate through the list for cla in (): # Index by value in the dictionary if j%3 == 0:# The first if is used to implement: serial number incrementing and line feeds print("\n") print(k,end = '.\t') k+=1 print(cla,end = '\t') if i%3 == 0:# The second if is used to implement: line breaks for each dictionary output print("\n") i+=1 j+=1 print("\n") return system()
4.exit_stu()
The function of this segment: human-computer interaction, exit
def exit_stu(): x = input("whether to withdraw or not?( YES or NO ) : ") if x == 'YES': print("***Repl Closed*** ") else: return system()
5.system_stu()
main function
def system(): print("=================================") print("Student Management System v1.0") print("1. Add student information") print("2. Deletion of student information") print("3. Display all student information") print("0. Exit the system.") print("=================================") x = int(input("Please enter the number corresponding to the function: ")) if( x == 1): add_stu() elif( x == 2): del_stu() elif( x == 3): print_stu() elif( x == 0): exit_stu() else: return system()
Full Code
stu = [] def add_stu(): newstu = { 'num':int(input("Please enter your school number:"'')), 'name':input("Please enter your name:"''), 'sex':input("Please enter gender:"'') } (newstu) return system() def del_stu(): delstus = int(input("Please enter the student's student number to be deleted:")) k = 0 for temp in stu: k+=1 if delstus in range(temp['num'],temp['num']-1,-1): print("The student number has been found.") break del stu[( k - 1 )] print("Deleted successfully.") return system() def print_stu(): i = 1 j = 0 k = 1 print("=================================") print("The student information is as follows:") print("=================================") print("Serial No. \t School No. \t Name \t Sex") for s in stu: for cla in (): if j%3 == 0: print("\n") print(k,end = '.\t') k+=1 print(cla,end = '\t') if i%3 == 0: print("\n") i+=1 j+=1 print("\n") return system() def exit_stu(): x = input("whether to withdraw or not?( YES or NO ) : ") if x == 'YES': print("***Repl Closed*** ") else: return system() def system(): print("=================================") print("Student Management System v1.0") print("1. Add student information") print("2. Deletion of student information") print("3. Display all student information") print("0. Exit the system.") print("=================================") x = int(input("Please enter the number corresponding to the function: ")) if( x == 1): add_stu() elif( x == 2): del_stu() elif( x == 3): print_stu() elif( x == 0): exit_stu() else: return system() system()
difficulty
1. In the list, index the dictionary by school number
2. Line feeds and serial numbers when printing lists
summarize
The above is a small introduction to the use of Python to realize the student registration management system, I hope to help you, if you have any questions please leave me a message, I will promptly reply to you. I would also like to thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and please note the source, thank you!