SoFunction
Updated on 2024-11-21

How to Write an Electronic Attendance System in Python

Experimental Project Introduction

在这里插入图片描述

在这里插入图片描述

The school now needs to implement an electronic attendance system, taking into account that your class has learned Python, a big data application development language, and is ready to let you implement some of the student-side attendance functions. After communicating with the teacher, you understand that:
(1) At present, the system has been partially realized by the seniors, you only need to complete the remaining functions, and the functions that need to be completed by you will be used.
The #todo is labeled, and the todo is followed by a list of the functions of the place, in the following form.

在这里插入图片描述

(2) Student information is stored in the stu_infos.csv file, the first line is the column name line, and each subsequent line is a student's information, including student number, name, and password. The content is in the following form:

在这里插入图片描述

(3) Attendance records will eventually be saved to a file, the first line is the column name line, and each subsequent line represents a student's attendance information, including student number, name, time, and attendance status (there are only four statuses: Attendance, Tardy, Leave, and Absence). The content format is as follows:

在这里插入图片描述

(4) Student information needs to be loaded into the student_infos list first, each element in student_info is a dictionary, the keys in the dictionary are the names of the respective columns, and the values are the contents of each row, according to the example data constructed student_infos list is as follows.

在这里插入图片描述

(5) The teacher's side of the attendance system has a total of two Python files, a file, which serves as the entry program file to implement the main framework, the main process is: load data login add attendance data; a stu_attendance.py file, which defines the functions of data loading, logging in and so on.

Answer Requirements:
(1) Add a line of your own information at the end of the stu_info.csv file, the password is optional, the name and student number must be your own.
(2) Look at the todo comments in the two Python files, add the appropriate code, and eventually provide the added code.
(3) Test the function of the program and provide screenshots of the program running. Use your student number for login verification and test the following two branches: if the login fails three times, and if the login succeeds, the attendance data will be added successfully.

additional functionality

Add a query function to enter a student's name to get information about his or her attendance data.

import module

import csv
import time
student_infos = []

Load data

def load_stu_info():
  """
  Loading student information
  Loading data from stu_infos.csv file
  :return: none
  """
  with open(r"stu_infos.csv", encoding='utf-8-sig') as file:
    f_csv = (file)
    header = next(f_csv)
    for row in f_csv:
      student_info = {}
      for index in range(3):
        student_info[header[index]] = row[index]
      student_infos.append(student_info)

log in

def login():
  """
  The user logs in with the student number and password
  Let the user login up to three times, if the login fails three times in a row (username or password is wrong), as long as the password and user are correct, the login is successful
  :return:Login successful return True and school number, three times failed login return False and None
  """
  retry_time = 0
  while retry_time < 3:
    user_no = input('Please enter login account:')
    password = input('Please enter the password:')
    for i in student_infos:
      if i['no']==user_no and i['password']==password:
        return True,user_no
    print('The username or password is incorrect!!!! Please re-enter.')
    retry_time += 1
  else:
    return False, None

Attendance record writing

def add(user_no):
  for x in student_infos:
    if user_no==x['no']:
      name=x['name']
      break
  times=("%Y-%m-%d %H:%M:%S", ())
  choices=['Attendance','Late','Leave of absence','Absenteeism']
  a=int(input("\tThe student's attendance: 1-attendance\t2-tardy\t3-excused\t4-absent:"))
  if a==1:
    data=choices[0]
  elif a==2:
    data=choices[1]
  elif a==3:
    data=choices[2]
  else:
    data=choices[3]
  with open(r"",'a+',newline='', encoding='utf-8') as f:
    wf = (f)
    ([user_no,name,times,data])# Write a line of data
    print("{}study at the same school{}Data has been written successfully!The operating time is{}".format(name,data,times))

Check Attendance Records

def select():
  student = []
  with open(r"", encoding='utf-8-sig') as file:
    f_csv = (file)
    header = next(f_csv)
    for row in f_csv:
      students = {}
      for index in range(4):
        students[header[index]] = row[index]
      (students)
    name=input("Please enter the name you need to find:")
    print(" student number\t\tname and surname\t\toperating time\t\tattendance status")
    for a in student:
      if a['name']==name:
        print(a['no']+'\t'+a['name']+'\t'+a['time']+'\t\t'+a['state'])
      else:
        print("None of that!!!")
        break

I will not give the main function, you can write your own if you need, if you need to private message me or download the dataset and source code here, yo!

Click to download!

Check out the running results yo!

在这里插入图片描述在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

each word of the text

Creative ideas come from the subtle tastes of life, don't be proud and don't be impatient, that's the way to go!

To this article on Python to write an electronic attendance system is introduced to this article, more related to Python to write an electronic attendance system content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future!