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

Using Python to compile student achievement management system (with source code)

編輯:Python
In the usual games , We are Excel After the data is written in it , You need to click the button to rank , Xiao Wang felt a little annoyed , As a powerful programming language Python, Can't you ? The answer is , Certainly. !
Project description : After program running , Prompt the user to have an option menu , Users can enter scores according to the menu , Easy and convenient , Check at any time !
Related to knowledge : Tuple list , Conditional statements , loop , character string , Simple algorithm , Dictionaries , function


Tuple algorithm
# -*- coding : utf-8 -*-
# @Time : 2020/8/8
# @author :  Wang Xiaowang
# @Software : PyCharm
# @CSDN : https://blog.csdn.net/weixin_47723732

scores = []
choice = None
print('''
  Score entry applet
 0 -  End procedure
 1 -  Enter the name score and enter
 2 -  Print the results after ranking
 3 -  Find grades for specific students
 4 -  Delete grades for specific students
 ''')
while choice != "0":
 choice = input("Choice: ")
 if choice == "0":
 print(" End procedure !")
 elif choice == "1":
 name = input(" Enter a name : ")
 score = int(input(" Enter grades : "))
 listing = (score, name)
 scores.append(listing)
 scores.sort(reverse=True)
 elif choice == "2":
 print("  Results ranking ")
 print(" full name \t achievement ")
 for listing in scores:
 score, name = listing
 print(name, "\t", score)
 elif choice == "3":
 Name = input(" Enter the name you want to find :")
 for each in scores:
 if each[1] == Name:
 score ,name=each
 print(" full name \t achievement ")
 print(name, "\t", score )
 elif choice == "4":
 Name = input(" Enter the name of the grade you want to delete : ")
 for each in scores:
 if each[1] == Name:
 scores.remove(each)
 else:
 print(" The choice you entered is wrong , Please check !")
input("\n\nPress the enter key to exit.")




Dictionary algorithm
# -*- coding : utf-8 -*-
# @Time : 2020/8/8
# @author :  Wang Xiaowang
# @Software : PyCharm
# @CSDN : https://blog.csdn.net/weixin_47723732


#  All student data is saved to a list , Each student's information is represented in a dictionary [{},{}]
records = []


def print_menu():
 """
  Print out the entire menu
 :return:
 """
 print("""
  Student information system

 0 -  sign out
 1 -  Show all student information
 2 -  Add student information
 3 -  Search for student information
 4 -  Delete student information
 5 -  Sort
 """)


def user_choice():
 """
  Get user input , And make sure that the input data is in 0-4 Between
 :return:  Returns the legal user selection
 """
 choice = input(" Please select (0~5):")
 #  Make sure the user's choice is in the 0~4
 while int(choice) > 5 or int(choice) < 0:
 choice = input(&quot; Please reselect (0~5):&quot;)

 return choice


def add_record():
 &quot;&quot;&quot;
  Add user data
 :return:
 &quot;&quot;&quot;
 name = input(' Please enter the name of the student :')
 while name == '':
 name = input(' Please enter the name of the student :')

 #  Determine whether the student information has been entered
 for info in records:
 if info['name'] == name:
 print(&quot; The student already exists &quot;)
 break
 else:
 score = float(input(' Please enter the grade (0~100):'))
 while score < 0 or score > 100:
 score = float(input(' Please enter the grade (0~100):'))

 info = {
 'name': name,
 'score': score
 }

 records.append(info)


def display_records():
 &quot;&quot;&quot;
  Display data
 :return:
 &quot;&quot;&quot;
 print(&quot; All student information &quot;)
 for info in records:
 print(&quot; full name :&quot;, info['name'], ' achievement :', info['score'])


def search_record():
 &quot;&quot;&quot;
  Look up the information according to the student's name , And output the students' scores
 :return:
 &quot;&quot;&quot;
 name = input(' Please enter the name of the student :')
 while name == '':
 name = input(' Please enter the name of the student :')

 for info in records:
 if info['name'] == name:
 print(&quot; Student achievement is :&quot;, info['score'])
 break
 else:
 print(&quot; There is no such student &quot;)


def del_record():
 &quot;&quot;&quot;
  Delete data according to student name
 :return:
 &quot;&quot;&quot;
 name = input(' Please enter the name of the student :')
 while name == '':
 name = input(' Please enter the name of the student :')

 for info in records:
 if info['name'] == name:
 records.remove(info)
 break
 else:
 print(&quot; There is no such user &quot;)


choice = None

while choice != &quot;0&quot;:
 #  Print menu
 print_menu()

 #  Get user input
 choice = user_choice()

 #  Use conditional branching to determine various options
 if choice == '1':
 #  Display the data
 display_records()
 elif choice == '2':
 #  Add a student data
 add_record()
 elif choice == '3':
 #  find information
 search_record()
 elif choice == '4':
 #  Delete data
 del_record()
 elif choice == '5':
 records.sort(key=lambda item: item['score'])

 elif choice == '0':
 #  Exit procedure
 print(' Welcome to login this system next time ')
 else:
 print(' Wrong choice !!!')


You can try it yourself !
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved