1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

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

        共 7288字,需瀏覽 15分鐘

         ·

        2022-11-04 03:45

        ???? 關注后回復 “進群” ,拉你進程序員交流群 ????

        來源丨網(wǎng)絡

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

        項目簡介

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

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

        #todo的形式進行標注, todo后面會列出這個地方的功能,形式如下。

        d60bd33413930692fc56f919e991febf.webp

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

        2ccf80913e7c3b6d77bbb0f9556e0219.webp

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

        17ac4ce7f86a38eda8e9e400f903d869.webp

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

        e71f78429c858ac295ebee264f353ff9.webp

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

        答題要求

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

        附加功能

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

        導入模塊

              import csv
        import time
        student_infos = []

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

              def load_stu_info():
            """
            加載學生信息
            從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():
            """
            用戶使用學號和密碼進行登錄
            最多讓用戶登錄三次,如果連續(xù)三次都登錄失?。ㄓ脩裘蛘呙艽a錯誤),只要密碼和用戶都正確表示登錄成功
            :return:登錄成功返回True和學號,三次都登錄失敗返回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該學生出勤情況: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("{}同學{}數(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("  學號\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('登錄失敗')

        看看運行效果喲!

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

        來源:blog.csdn.net/weixin_47723732


        -End-

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

        385194f023cf356c9ed32671d8e2f888.webp

        點擊??卡片,關注后回復【面試題】即可獲取

        在看點這里 bbd7bc787320e52499fcce0ef1f1cad1.webp好文分享給更多人↓↓

        瀏覽 46
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            中文字幕日韩精品人妻在线视频 | free性老太80hd性bbw | 啊啊啊操逼 | 办公室挺进美艳老师后臀 | 久久久久久久久久久久影院 | 鸡巴操美女 | 小泽玛利亚强忍高潮 | 日本少妇xxxx | 明星换脸av一区二区三区网站 | 亚洲精品视频在线 |