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

Using Python to compile student grade calculation system

編輯:Python
Let's take a simple example , We all know the grades in the University , It's not the final word , But there are a lot of achievements and different proportions , Finally, there will be a total score , So paying attention to details is the most important ! Let's take a look at this !
Project requirements : There is one CSV The document contains the scores of many students ( A lot of usual results , And the name , Student number ), What this program does is , Use specified algorithms and rules , Calculate the total score , And then rank , Print out the achievement information of each stage as the teaching and research reform . At the same time, the output must be good-looking , write in TXT File file !
Related to knowledge :Python All grammar !
Project features : Formatted print , Make the output more beautiful and intuitive , Function structure , Help code read , Project portability , Simple and easy to understand
Parsing files
def csv_students():
 global student_infos
 import csv
 student_infos = []
 with open(r" Detailed results .csv", encoding='utf-8-sig') as file:# Put your CSV The file and the program file are placed under the same folder
 f_csv = csv.reader(file)
 header = next(f_csv)
 for row in f_csv:
 student_info = {}
 for index in range(6):
 student_info[header[index]] = row[index]
 student_infos.append(student_info)
 #  Format print function , Make its output align automatically
 add_print1()

Parse its file , Then show it in the form of a dictionary , But the code is optimized here , Make the print look good . Here we import CSV This library , For some of its properties, the operation Syntax , We can have a look at Baidu . First
We set up a list to store all of the dictionaries later , Then I opened the file , And use .reader() Read header information , Then take out the header , This will facilitate our subsequent operations .next()
Then we create the dictionary with a loop , The keys and values in each dictionary are added by ourselves .6 Each title ,6 Messages , We will complete the key and value matching , This creates a complete dictionary , Finally, until we have read these things completely , The cycle is over .
Realization effect :

Calculate the score
def scores_students():
 for scores in student_infos:
 total = float(scores[" experiment 1"]) * 1 / 10 + float(scores[" experiment 2"]) * 1 / 10 + \
 float(scores[" experiment 3"]) * 2 / 10 + float(scores[" Final grade "]) * 6 / 10
 scores[" Overall score "] = total
 #  Rank according to the overall evaluation results , And print it out ( Additional features )
 student_infos.sort(key=lambda item: item[" Overall score "], reverse=True)
 i = 0
 for score in student_infos:
 i += 1
 score[" Class ranking "] = i
 add_print2()
 import json
 #  Will be resolved after CSV file , Convert to python object , And stored in a file ( Additional features )
 with open(r"student.txt", "w", encoding="utf_8") as file:
 json.dump(student_infos, file, ensure_ascii=False, indent=0)



Segmented printing
def grad_students():
 num1 = 0
 num2 = 0
 num3 = 0
 num4 = 0
 num5 = 0
 for scores in student_infos:
 grade = float(scores[" Overall score "])
 if grade < 60:
 num1 += 1
 elif grade >= 60 and grade < 70:
 num2 += 1
 elif grade >= 70 and grade < 80:
 num3 += 1
 elif grade >= 80 and grade < 90:
 num4 += 1
 elif grade >= 90 and grade <= 100:
 num5 += 1
 all = int(num1 + num2 + num3 + num4 + num5)
 print(&quot;\t The total number of people is %s people &quot; % (all))
 #  Print out the number and proportion of fractional segments
 print(&quot;\t[0, 60) There are  {} people  &quot;.format(num1), &quot;\t Accounted for as {}&quot;.format(str(num1 / all * 100)[:4] + &quot;%&quot;))
 print(&quot;\t[60,70) There are {} people &quot;.format(num2), &quot;\t Accounted for as {}&quot;.format(str(num2 / all * 100)[:4] + &quot;%&quot;))
 print(&quot;\t[70,80) There are {} people &quot;.format(num3), &quot;\t Accounted for as {}&quot;.format(str(num3 / all * 100)[:4] + &quot;%&quot;))
 print(&quot;\t[80,90) There are {} people &quot;.format(num4), &quot;\t Accounted for as {}&quot;.format(str(num4 / all * 100)[:4] + &quot;%&quot;))
 print(&quot;\t[90,100] There are {} people &quot;.format(num5), &quot;\t Accounted for as {}&quot;.format(str(num5 / all * 100)[:4] + &quot;%&quot;))


Find students
def find_students():
 while True:
 study_num = input(&quot; Please enter the student number you want to find : &quot;)
 for score in student_infos:
 if score[&quot; Student number &quot;] == study_num:
 print(&quot; full name :&quot;, score[&quot; full name &quot;], &quot; Student number :&quot;, score[&quot; Student number &quot;], &quot; experiment 1:&quot;,
 score[&quot; experiment 1&quot;], &quot; experiment 2:&quot;, score[&quot; experiment 2&quot;], &quot; experiment 3:&quot;,
 score[&quot; experiment 3&quot;], &quot; Final grade :&quot;, score[&quot; Final grade &quot;], &quot; Overall score :&quot;,
 score[&quot; Overall score &quot;], &quot; Class ranking :&quot;, score[&quot; Class ranking &quot;])
 continue




It's over , Of course, here we call it a back-end development project , Generally, we call it graphical interface operation development in our mobile phone or educational administration system , This requires our later knowledge .
Click here to download the source code for operation !!!
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved