程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

A typical case of Python based functions - student management system

編輯:Python

About bloggers : Former Internet manufacturer tencent staff , Network security giant Venustech staff , Alibaba cloud development community expert blogger , WeChat official account java Quality creators of basic notes ,csdn High quality creative bloggers , Entrepreneur , Knowledge sharers , Welcome to your attention , give the thumbs-up , Collection .

Catalog

      • One 、 background
      • Two 、 Typical cases - Student management system
      • 3、 ... and 、 Reference resources
      • Four 、 summary


One 、 background

In the actual development process , You will often encounter many identical or very similar operations , At this time , Code that implements similar operations can be encapsulated as functions , Then call the function where you need it . This can not only realize code reuse , It can also make the code more organized , Increase code reliability . Now let's introduce python Function of the typical case of student management system related content .


Two 、 Typical cases - Student management system

example : Design a student management system , Complete the basic information of students ( Including student ID 、 Name and gender ) The input of 、 Delete and view functions . Copy to pycharm To view the , Very easy to understand .

# Show all student information 
def showStuInfo():
print("=" * 20)
print(" The student information is as follows :")
print("=" * 20)
print(" Serial number Student number full name Gender ")
i = 1
# Traverse the list storing student information , Output the details of each student 
for tempInfo in stuInfos:
print("%d %s %s %s" % (i, tempInfo['num'],tempInfo['name'], tempInfo['sex']))
i += 1
stuInfos=[] # Used to keep all the information of students 
def printMenu(): # Printing function prompt 
print("="*20)
print(" Student management system V1.0 ")
print("1. Add student information ")
print("2. Delete student information ")
print("3. Show all student information ")
print("0. Exit the system ")
print("="*20)
# Add a student information 
def addStuInfo():
newNum = input(" Please enter the student number of the new student :") # Prompt and get the student's student number 
newName = input(" Please enter the name of the new student :") # Prompt and get the student's name 
newSex = input(" Please enter the gender of the new student ( male / Woman ):") # Prompt and get the student's gender 
newInfo = {
} # Definition dictionary 
# assignment 
newInfo['num'] = newNum
newInfo['name'] = newName
newInfo['sex'] = newSex
stuInfos.append(newInfo) # Add elements to the list 
# Delete a student information 
def delStuInfo(student):
del_num = input(" Please enter the student ID of the student you want to delete :") # Prompt and obtain student ID 
for stu in student: # Traverse the list 
if stu['num'] == del_num: # Judge whether it is the same as the entered student number 
student.remove(stu) # Delete the student information 
#main Functions control the flow of the entire program 
def main():
while True:
printMenu() # Print function menu 
key = input(" Please enter the number corresponding to the function ") # Get user input 
if key == '1': # Add student information 
addStuInfo()
if key == '2': # Delete student information 
delStuInfo(stuInfos)
elif key == '3': # Show student information 
showStuInfo()
elif key == '0': # Exit loop 
quit_con = input(" Are you sure to quit? ?(Yes or No):")
if quit_con == 'Yes':
break
main() # call main function 

give the result as follows .


3、 ... and 、 Reference resources

1、 Liao Xuefeng's official website
2、python Official website
3、Python Programming case tutorial


Four 、 summary

The above is about Python The function of a typical case of student management system related knowledge , You can refer to it , If you think it's good , Welcome to thumb up 、 Collection 、 Looking at , Welcome to wechat search java Basic notes , Relevant knowledge will be continuously updated later , Make progress together .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved