<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          用 Python 寫了一個電子考勤系統(tǒng)!

          共 7288字,需瀏覽 15分鐘

           ·

          2022-11-04 03:45

          ???? 關(guān)注后回復(fù) “進(jìn)群” ,拉你進(jìn)程序員交流群 ????

          來源丨網(wǎng)絡(luò)

          今天給大家分享一個比較有意思的Python應(yīng)用,用 Python 寫了一個電子考勤系統(tǒng),源碼已在文章全部給出,記得點(diǎn)贊收藏哦~

          項(xiàng)目簡介

          學(xué)?,F(xiàn)在需要實(shí)現(xiàn)一個電子考勤系統(tǒng),考慮到你們班已經(jīng)學(xué)過大數(shù)據(jù)應(yīng)用開發(fā)語言Python,準(zhǔn)備讓你們實(shí)現(xiàn)部分學(xué)生端考勤功能。經(jīng)過和老師的溝通,你了解到:

          (1) 目前該系統(tǒng)已經(jīng)被學(xué)長實(shí)現(xiàn)了部分功能,你們只需要完成剩余功能即可,需要你們完成的功能會使用

          #todo的形式進(jìn)行標(biāo)注, todo后面會列出這個地方的功能,形式如下。

          d60bd33413930692fc56f919e991febf.webp

          (2) 學(xué)生信息存儲在stu_infos.csv文件中,第一行是列名行,后面每一行都是一個學(xué)生的信息,包含學(xué)號,姓名,密碼。內(nèi)容形式如下:

          2ccf80913e7c3b6d77bbb0f9556e0219.webp

          (3) 考勤記錄最終會被保存到attendance.csv文件中,第一行是列名行,后面每一行代表一個學(xué)生的考勤信息,包含學(xué)號,姓名,時間,考勤狀態(tài)(只有出勤、遲到、請假、缺勤四種狀態(tài))。內(nèi)容格式如下:

          17ac4ce7f86a38eda8e9e400f903d869.webp

          (4) 學(xué)生信息需要首先被加載到student_infos列表中,student_info中的每個元素都是一個字典,字典中的鍵都是各自列名,而值則是每一行內(nèi)容,按照示例數(shù)據(jù)構(gòu)造出來的student_infos列表如下。

          e71f78429c858ac295ebee264f353ff9.webp

          (5) 考勤系統(tǒng)老師端總共有兩個Python文件,一個main.py文件,該文件作為入口程序文件,實(shí)現(xiàn)主體框架,主體流程就是:加載數(shù)據(jù) 登錄 添加考勤數(shù)據(jù);一個stu_attendance.py文件,定義了數(shù)據(jù)加載、登錄等函數(shù)。

          答題要求

          1. 在stu_info.csv文件末尾添加一行自己的信息,密碼隨意寫,名字和學(xué)號必須是自己
          2. 查看兩個Python文件中的todo注釋,添加合適代碼,最終提供添加的代碼。
          3. 測試程序功能,提供程序運(yùn)行截圖。進(jìn)行登錄驗(yàn)證的時候使用自己的學(xué)號進(jìn)行登錄驗(yàn)證,并且需要測試如下2個分支:3次都登錄失敗的情況、登錄成功后成功添加考勤數(shù)據(jù)。

          附加功能

          添加一個查詢功能,輸入一個學(xué)生的姓名就可以獲取他的出勤數(shù)據(jù)信息

          導(dǎo)入模塊

                import csv
          import time
          student_infos = []

          加載數(shù)據(jù)

                def load_stu_info():
              """
              加載學(xué)生信息
              從stu_infos.csv文件中加載數(shù)據(jù)
              :return: 無
              """

              with open(r"stu_infos.csv", encoding='utf-8-sig'as file:
                  f_csv = csv.reader(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)

          登錄

                def login():
              """
              用戶使用學(xué)號和密碼進(jìn)行登錄
              最多讓用戶登錄三次,如果連續(xù)三次都登錄失?。ㄓ脩裘蛘呙艽a錯誤),只要密碼和用戶都正確表示登錄成功
              :return:登錄成功返回True和學(xué)號,三次都登錄失敗返回False和None
              """

              retry_time = 0
              while retry_time < 3:
                  user_no = input('請輸入登錄賬號:')
                  password = input('請輸入密碼:')
                  for i in student_infos:
                      if i['no']==user_no and i['password']==password:
                          return True,user_no
                  print('用戶名或者密碼錯誤?。?!請重新輸入。')
                  retry_time += 1
              else:
                  return FalseNone

          考勤記錄寫入

                def add(user_no):
              for x in student_infos:
                  if user_no==x['no']:
                      name=x['name']
                      break
              times=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
              choices=['出勤','遲到','請假','缺勤']
              a=int(input("\t該學(xué)生出勤情況:1-出勤\t2-遲到\t3-請假\t4-缺勤:"))
              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"attendance.csv",'a+',newline='', encoding='utf-8'as f:
                  wf = csv.writer(f)
                  wf.writerow([user_no,name,times,data])#寫入一行數(shù)據(jù)
                  print("{}同學(xué){}數(shù)據(jù)已經(jīng)寫入成功!操作時間是{}".format(name,data,times))

          查詢考勤記錄

                def select():
              student = []
              with open(r"attendance.csv", encoding='utf-8-sig'as file:
                  f_csv = csv.reader(file)
                  header = next(f_csv)
                  for row in f_csv:
                      students = {}
                      for index in range(4):
                          students[header[index]] = row[index]
                      student.append(students)
                  name=input("請輸入你需要查找的姓名:")
                  print("  學(xué)號\t\t姓名\t\t操作時間\t\t出勤狀態(tài)")
                  for a in student:
                      if a['name']==name:
                          print(a['no']+'\t'+a['name']+'\t'+a['time']+'\t\t'+a['state'])
                      else:
                          print("無此人!?。?)
                          break

          主函數(shù)main.py

                from student.stu_attendance import *
          if __name__ == '__main__':
              load_stu_info()
              success, stu_no = login()
              print(stu_no)
              if success:
                  print('登錄成功!')
                  add(stu_no)
                  q=int(input("你想要查詢出勤數(shù)據(jù)嗎?\tyes(1)--no(0)"))
                  if q==1:
                      select()
                  else:
                      print("歡迎下次登錄電子考勤系統(tǒng)")
              else:
                  print('登錄失敗')

          看看運(yùn)行效果喲!

          821162b33b87bdf6d9d5969a5b2022c9.webp 39b75f015795f95faa4dd70de303dd6b.webp d42d91400511cfda6ba96d841a11612b.webp babd26c7379d4f4482cf25059212c5cc.webp

          來源:blog.csdn.net/weixin_47723732


          -End-

          最近有一些小伙伴,讓我?guī)兔φ乙恍?nbsp;面試題 資料,于是我翻遍了收藏的 5T 資料后,匯總整理出來,可以說是程序員面試必備!所有資料都整理到網(wǎng)盤了,歡迎下載!

          385194f023cf356c9ed32671d8e2f888.webp

          點(diǎn)擊??卡片,關(guān)注后回復(fù)【面試題】即可獲取

          在看點(diǎn)這里 bbd7bc787320e52499fcce0ef1f1cad1.webp好文分享給更多人↓↓

          瀏覽 46
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  久久99久久久久久久久久久 | 亚洲一级黄片免费观看视频洲免费观看 | 欧美肏屄网站 | 十八女人高潮A片免费 | 无码电影网 |