美文网首页
英语录音检查程序

英语录音检查程序

作者: AndyDennisRob | 来源:发表于2020-03-07 14:54 被阅读0次

    为了检查录音,可笔者比较懒,不想一个一个对着。特意写了个python程序来统计。前提需要知道已完成作业的学生的编号。

    安装必要的库

    pip install xlrd
    pip install xlwt
    pip install xlutils
    

    程序部分

    首先,引入需要import的库/类

    import xlrd
    import xlwt
    from xlutils.copy import copy
    import sys
    

    接收输入进来的学生到数组中,并且返回

    def inputDone():
        # 非-1持续输入
        j = eval(input("请输入已完成的学生编号: "))
        doneS = []
        while j != -1:
            doneS.append(j)
            j = eval(input("请输入已完成的学生编号: "))
        print("--------输入已完成学生编号完毕----------")
        return doneS
    

    标记已完成的学生

    def noteDone(file, time, doneS, sheet_index=0):
        workbook = xlrd.open_workbook(file)
        wb = copy(workbook)
        ws = wb.get_sheet(sheet_index)
        for num in doneS:
            ws.write(num - 1, time, "完成")
        wb.save(file)
        print("---------写入已完成作业完成----------")
    

    找出未完成的学生

    def findUndo(file, time, sheet_index=0):
        workbook = xlrd.open_workbook(file)
        sheet = workbook.sheet_by_index(sheet_index)
        undo = []
        for i in range(1, sheet.nrows):
            cell_value = sheet.cell(i, time).value
            if cell_value != '完成':
                undo.append(sheet.cell(i, 0).value)
        print("----------找出未完成作业的学生完毕-----------")
        return undo
    

    将未完成的学生写入sheet2

    def writeUndo(file, time, undoS, sheet_index=1):
        workbook = xlrd.open_workbook(file)
        wb = copy(workbook)
        ws = wb.get_sheet(sheet_index)
        sheet = workbook.sheet_by_index(sheet_index)
        row = 1
        for i in range(1, sheet.nrows):
            ws.write(i, time - 1, " ")
        for name in undoS:
            # print(name)
            ws.write(row, time - 1, name)
            row += 1
        wb.save(file)
        print("----------写入未完成作业名单完毕------------")
    

    main函数

    if __name__ == '__main__':
        # 操作的文件
        file = 'Excel/test.xlsx'
        # 第几次作业
        time = 2
        # doneS = inputDone()
        # 请不要输入 1
        doneS = [3, 5]
        if 1 in doneS:
            print("1 不允许在已完成的学生编号中")
            sys.exit()
        print("第{}次作业已完成学生的编号: {}".format(time, doneS))
        noteDone(file, time, doneS)
        undo = findUndo(file, time)
        print("未完成的学生: ", undo)
        writeUndo(file, time, undo)
    
        print("----> 感谢使用  <----")
    

    这是我的项目结构,其实很简单的。


    项目结构
    运行结果
    sheet1,同学名单
    sheet2,未完成同学名单

    这里第一次作业不管哦,是之前演示的。如果你想修改第一次作业的数据,只需把main函数中的time改为1即可。
    hhha,我真是一个懒惰的英语助手。

    相关文章

      网友评论

          本文标题:英语录音检查程序

          本文链接:https://www.haomeiwen.com/subject/cvjcdhtx.html