Python+Excel数据分析实战:军事体能考核成绩评定(七)3公里计算

本文主要是介绍Python+Excel数据分析实战:军事体能考核成绩评定(七)3公里计算,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这一章我们实现男子和女子3000米跑成绩的计算,原始数据是时间,多少分多少秒,全年龄段考核内容都是3公里,但是海拔不同标准不同,是所有科目中最复杂的计算。

一、基本情况

通过分析3000米跑“成绩计算标准表”,发现标准表也只是参照标准表,不是连续的全覆盖。比如平原3000米标准中24岁以下男子,只规定了11分30秒的成绩为100分,11分55秒的成绩为95分,那么中间的情况多少分呢?

男子3000米成绩计算标准表
女子3000米成绩计算标准表
高原男子3000米成绩计算标准表
高原女子3000米成绩计算标准表

还是只能是我们根据公平原则去补充,在11分30秒、11分55秒的成绩之间去取平均分,但手工补充的数据量太大,我们编程解决。

所以录入Excel表中的标准和规定的相同,没有增加手工计算的标准:
男女平原3000米标准
男子高原3000米标准
女子高原3000米标准

同样,通过Python的openpyxl模块读取标准表中的数据,制成 {原始3公里跑时长:分数} 格式的字典,以供主程序查询出换算成绩,再写入成绩表的对应位置中。

这里要使用海拔数据,后期等级评定还需要人员类别的信息,所以设计了一个工作簿来输入这些参数信息。
人员参数设置

在B2位置输入人员类别,在B3位置输入海拔。

二、代码实现

原始成绩登记表

1.我把计算高原男子和女子3000米的文件分开,同时海拔3000以下与3000米以上标准又不同,这里我以男子2001米~3000米的计算为例讲解,文件命名为highland2001up_3km_male.py。这个模块类的构造方法“__init__()” 有一个参数,ele,传递海拔数据。

另外将 {原始3公里跑时长:分数} 格式的字典的键全部取出来,转换成列表,如24岁以下的时间键,age24_keys=[datetime.time(0, 11, 42), datetime.time(0, 12, 7), datetime.time(0, 12, 22), datetime.time(0, 12, 37), datetime.time(0, 12, 52), datetime.time(0, 13, 7), datetime.time(0, 13, 22), datetime.time(0, 13, 42), datetime.time(0, 13, 47), datetime.time(0, 13, 52)]。目的是计算标准中未给出的中间值要用到,比如计算11分45秒的成绩,就需要与标准中有的11分42秒和12分7秒做计算。

还要根据海拔,计算出每增加100米高度标准递增8秒后的标准时间列表,因为2201米的标准比2000米~2100米的标准多了16秒。

# 男子海拔2001~3000米,3000米跑的成绩计算
# 从工作表“男子高原3000米标准”中读取数据import openpyxl
import datetime as dt
from run_standard_add import standard_add
from score_computing import score_computingclass Highland2001up3kmMaleStandardData:def __init__(self, ele):elevation = ele  # 海拔高度multiple = (elevation - 2001) // 100  # 整数除法返回向下取整后的结果addition = multiple * 8  # 每增加100米高度,标准递增8秒wb = openpyxl.load_workbook('通用训练课目考核成绩计算.xlsx')ws_long_run_male = wb['男子高原3000米标准']self.age24 = {}     # 24岁以下,{原始男子3000米分秒数:分数}self.age25_27 = {}  # 25~27岁,{原始男子3000米分秒数:分数}self.age28_30 = {}self.age31_33 = {}self.age34_36 = {}self.age37_39 = {}self.age40_42 = {}  # 40岁以上,{原始男子3000米分秒数:分数}self.age43_45 = {}  # 43~45岁,{原始男子3000米分秒数:分数}self.age46_48 = {}self.age49_51 = {}self.age52_54 = {}self.age55_57 = {}self.age58_59 = {}rngs2000 = ws_long_run_male.iter_rows(min_row=3,max_row=12,min_col=2,max_col=15)# 生成{原始男子3000米分秒数:分数}的字典for row in rngs2000:# print([c.value for c in row])self.age24[row[1].value] = row[0].valueself.age25_27[row[2].value] = row[0].valueself.age28_30[row[3].value] = row[0].valueself. age31_33[row[4].value] = row[0].valueself.age34_36[row[5].value] = row[0].valueself.age37_39[row[6].value] = row[0].valueself.age40_42[row[7].value] = row[0].valueself.age43_45[row[8].value] = row[0].valueself.age46_48[row[9].value] = row[0].valueself.age49_51[row[10].value] = row[0].valueself.age52_54[row[11].value] = row[0].valueself.age55_57[row[12].value] = row[0].valueself.age58_59[row[13].value] = row[0].value# print('-----age24-----') # 打印数据以便检查# for m in self.age24.items():#     print(m)# print('-----age25_27-----')# for m in self.age25_27.items():#     print(m)# print('-----age28_30-----')# for m in self.age28_30.items():#     print(m)# print('-----age31_33-----')# for m in self.age31_33.items():#     print(m)# print('-----age34_36-----')# for m in self.age34_36.items():#     print(m)# print('-----age37_39-----')# for m in self.age37_39.items():#     print(m)## print('-----age40_42-----')  # 打印数据以便检查# for m in self.age40_42.items():#     print(m)# print('-----age43_45-----')# for m in self.age43_45.items():#     print(m)# print('-----age46_48-----')# for m in self.age46_48.items():#     print(m)# print('-----age49_51-----')# for m in self.age49_51.items():#     print(m)# print('-----age52_54-----')# for m in self.age52_54.items():#     print(m)# print('-----age55_57-----')# for m in self.age55_57.items():#     print(m)# print('-----age58_59-----')# for m in self.age58_59.items():#     print(m)# 将字典中的时间键取出来,转换成列表self.age24_keys = list(self.age24.keys())#print(self.age24_keys)self.age25_27_keys = list(self.age25_27.keys())self.age28_30_keys = list(self.age28_30.keys())self.age31_33_keys = list(self.age31_33.keys())self.age34_36_keys = list(self.age34_36.keys())self.age37_39_keys = list(self.age37_39.keys())self.age40_42_keys = list(self.age40_42.keys())self.age43_45_keys = list(self.age43_45.keys())self.age46_48_keys = list(self.age46_48.keys())self.age49_51_keys = list(self.age49_51.keys())self.age52_54_keys = list(self.age52_54.keys())self.age55_57_keys = list(self.age55_57.keys())self.age58_59_keys = list(self.age58_59.keys())# 每增加100米高度标准递增8秒self.age24_time_list = standard_add(self.age24_keys.copy(),addition)#print(self.age24_time_list)self.age25_27_time_list = standard_add(self.age25_27_keys.copy(),addition)self.age28_30_time_list = standard_add(self.age28_30_keys.copy(),addition)self.age31_33_time_list = standard_add(self.age31_33_keys.copy(),addition)self.age34_36_time_list = standard_add(self.age34_36_keys.copy(),addition)self.age37_39_time_list = standard_add(self.age37_39_keys.copy(),addition)self.age40_42_time_list = standard_add(self.age40_42_keys.copy(),addition)self.age43_45_time_list = standard_add(self.age43_45_keys.copy(),addition)self.age46_48_time_list = standard_add(self.age46_48_keys.copy(),addition)self.age49_51_time_list = standard_add(self.age49_51_keys.copy(),addition)self.age52_54_time_list = standard_add(self.age52_54_keys.copy(),addition)self.age55_57_time_list = standard_add(self.age55_57_keys.copy(),addition)self.age58_59_time_list = standard_add(self.age58_59_keys.copy(),addition)

2.上面使用到的增加标准函数standard_add(),我写入在另一个模块run_standard_add.py中:

# 每增加100米高度标准递增8秒def standard_add(list, addition):'''每增加100米高度,标准递增8秒,这里将增加的秒数加到每个列表元素中'''for x in range(0, len(list)):seconds = list[x].second + additionminutes_add = seconds // 60  # 整数除法返回向下取整后的结果为分数的增值seconds_add = seconds % 60  # 取余数为秒数#print(minutes_add, seconds_add)list[x] = list[x].replace(minute=minutes_add + list[x].minute, second=seconds_add)return list

3.设计计算分数的方法,同样是先根据年龄进行判定,这里把计算方式再做了打包,做成了score_computing()函数,有4个参数,原始成绩,字典,时间键列表,每增加100米高度标准递增8秒后的时间键列表。

    def longrun_score_computing(self,age,original_amount):'''根据年龄,实际3000米分秒数,计算所得分数'''if type(original_amount) is dt.time:  # 核查是否是日期格式if age <= 24:return score_computing(original_amount,self.age24,self.age24_keys,self.age24_time_list)elif 25 <= age <= 27:return score_computing(original_amount, self.age25_27, self.age25_27_keys, self.age25_27_time_list)elif 28 <= age <= 30:return score_computing(original_amount, self.age28_30, self.age28_30_keys, self.age28_30_time_list)elif 31 <= age <= 33:return score_computing(original_amount, self.age31_33, self.age31_33_keys, self.age31_33_time_list)elif 34 <= age <= 36:return score_computing(original_amount, self.age34_36, self.age34_36_keys, self.age34_36_time_list)elif 37 <= age <= 39:return score_computing(original_amount, self.age37_39, self.age37_39_keys, self.age37_39_time_list)# 40~59elif 40 <= age <= 42:return score_computing(original_amount, self.age40_42, self.age40_42_keys, self.age40_42_time_list)elif 43 <= age <= 45:return score_computing(original_amount, self.age43_45, self.age43_45_keys, self.age43_45_time_list)elif 46 <= age <= 48:return score_computing(original_amount, self.age46_48, self.age46_48_keys, self.age46_48_time_list)elif 49 <= age <= 51:return score_computing(original_amount, self.age49_51, self.age49_51_keys, self.age49_51_time_list)elif 52 <= age <= 54:return score_computing(original_amount, self.age52_54, self.age52_54_keys, self.age52_54_time_list)elif 55 <= age <= 57:return score_computing(original_amount, self.age55_57, self.age55_57_keys, self.age55_57_time_list)elif 58 <= age <= 59:return score_computing(original_amount, self.age58_59, self.age58_59_keys, self.age58_59_time_list)else:print('ERROR:男子3000米跑,原始成绩的数据类型须为时间(datetime.time)类型')if __name__ == "__main__":   # 测试本模块hl2001_3km_male_std = Highland2001up3kmMaleStandardData(2901)result = hl2001_3km_male_std.longrun_score_computing(24,dt.time(0,13,4))print(result)

4.上面使用到的计算函数score_computing(),我写入在另一个模块score_computing.py中。小于55分和大于100分的情况很简单,之间的先判定是否刚好是标准中规定的时长,是的话,通过相同序号联系,直接查字典;不是的话,添加进每100米海拔增加时间后的列表中排序,得到序号,序号减1,和序号加1,就得到相邻的,两个标准表中有的时长。然后,计算上下两个标准时长的间隔秒数,以及与相邻较差标准时长的间隔秒数,最后算出最终成绩。

# 通过原始的3000米跑成绩,分年龄段计算成绩def score_computing(original_amount,age_n,age_n_keys,age_n_time_list):#print(age_n_keys)#print(age_n_time_list)if original_amount > age_n_time_list[9]:  # 大于55分的时长时,为0分return 0elif original_amount < age_n_time_list[0]:  #小于100分的时长时,加分return 100 + ((age_n_time_list[0].minute - original_amount.minute) * 60 +age_n_time_list[0].second - original_amount.second) / 5elif age_n_time_list[0] <= original_amount <= age_n_time_list[9]:if original_amount in age_n_time_list:index_1 = age_n_time_list.index(original_amount)   # 原始成绩在列表中的序号return age_n[age_n_keys[index_1]]else:l1 = age_n_time_list.copy()        # l1为临时表l1.append(original_amount); l1.sort()   # 添加原始成绩进列表,再排序index_2 = l1.index(original_amount)     # 原始成绩在列表中的序号better_time = l1[index_2 - 1]           # 比原始成绩优秀的最临近的标准成绩worse_time = l1[index_2 + 1]            # 比原始成绩差的最临近的标准成绩time_interval = (worse_time.minute - better_time.minute)*60 + (worse_time.second - better_time.second)       # 上下两个标准成绩的间隔秒数seconds_dif = (worse_time.minute - original_amount.minute)*60 + (worse_time.second - original_amount.second)   # 与相邻较差标准成绩的间隔秒数#print(time_interval, seconds_dif)return round(5*seconds_dif/time_interval+age_n[age_n_keys[index_2]],1)  #5是相邻两个标准时长的分数相差5分

5.女子2001米~3000米的计算文件命名为highland2001up_3km_female.py,除了读取的工作簿不同,其它内容与男子大体相同。

6.男子3001米~4000米的计算文件命名为highland3001up_3km_male.py,女子3001米~4000米的计算文件命名为highland3001up_3km_female.py。

7.平原男子和女子3000米写成了一个带性别参数的类,文件名为flatland_3km.py,根据性别参数,读取工作簿上不同区域的标准数据,制成不同的标准字典。因为没有每增加海拔100米增加时长的要求,在调用score_computing()函数时,第3/4参数使用同一个列表即可。

# 男子女子平原3000米跑的成绩计算
# 从工作表“男女平原3000米标准”中读取数据import openpyxl
import datetime as dt
from score_computing import score_computingclass Flatland3kmStandardData:def __init__(self, gender):self.gender = gender  # 性别wb = openpyxl.load_workbook('通用训练课目考核成绩计算.xlsx')ws_long_run = wb['男女平原3000米标准']self.age24 = {}     # 24岁以下,{原始男女平原3000米分秒数:分数}self.age25_27 = {}  # 25~27岁,{原始男女平原3000米分秒数:分数}self.age28_30 = {}self.age31_33 = {}self.age34_36 = {}self.age37_39 = {}self.age40_42 = {}  # 40岁以上,{原始男女平原3000米分秒数:分数}self.age43_45 = {}  # 43~45岁,{原始男女平原3000米分秒数:分数}self.age46_48 = {}self.age49_51 = {}self.age52_54 = {}self.age55_57 = {}self.age58_59 = {}if self.gender == '男':rngs = ws_long_run.iter_rows(min_row=3, max_row=12, min_col=1, max_col=14)elif self.gender == '女':rngs = ws_long_run.iter_rows(min_row=16,max_row=25,min_col=1,max_col=14)# 生成{原始男女平原3000米分秒数:分数}的字典for row in rngs:# print([c.value for c in row])self.age24[row[1].value] = row[0].valueself.age25_27[row[2].value] = row[0].valueself.age28_30[row[3].value] = row[0].valueself. age31_33[row[4].value] = row[0].valueself.age34_36[row[5].value] = row[0].valueself.age37_39[row[6].value] = row[0].valueself.age40_42[row[7].value] = row[0].valueself.age43_45[row[8].value] = row[0].valueself.age46_48[row[9].value] = row[0].valueself.age49_51[row[10].value] = row[0].valueself.age52_54[row[11].value] = row[0].valueself.age55_57[row[12].value] = row[0].valueself.age58_59[row[13].value] = row[0].value# print('-----age24-----') # 打印数据以便检查# for m in self.age24.items():#     print(m)# print('-----age25_27-----')# for m in self.age25_27.items():#     print(m)# print('-----age28_30-----')# for m in self.age28_30.items():#     print(m)# print('-----age31_33-----')# for m in self.age31_33.items():#     print(m)# print('-----age34_36-----')# for m in self.age34_36.items():#     print(m)# print('-----age37_39-----')# for m in self.age37_39.items():#     print(m)## print('-----age40_42-----')  # 打印数据以便检查# for m in self.age40_42.items():#     print(m)# print('-----age43_45-----')# for m in self.age43_45.items():#     print(m)# print('-----age46_48-----')# for m in self.age46_48.items():#     print(m)# print('-----age49_51-----')# for m in self.age49_51.items():#     print(m)# print('-----age52_54-----')# for m in self.age52_54.items():#     print(m)# print('-----age55_57-----')# for m in self.age55_57.items():#     print(m)# print('-----age58_59-----')# for m in self.age58_59.items():#     print(m)# 将字典中的时间键取出来,转换成列表self.age24_keys = list(self.age24.keys())#print(self.age24_keys)self.age25_27_keys = list(self.age25_27.keys())self.age28_30_keys = list(self.age28_30.keys())self.age31_33_keys = list(self.age31_33.keys())self.age34_36_keys = list(self.age34_36.keys())self.age37_39_keys = list(self.age37_39.keys())self.age40_42_keys = list(self.age40_42.keys())self.age43_45_keys = list(self.age43_45.keys())self.age46_48_keys = list(self.age46_48.keys())self.age49_51_keys = list(self.age49_51.keys())self.age52_54_keys = list(self.age52_54.keys())self.age55_57_keys = list(self.age55_57.keys())self.age58_59_keys = list(self.age58_59.keys())def longrun_score_computing(self,age,original_amount):'''根据年龄,实际3000米分秒数,计算所得分数'''if type(original_amount) is dt.time:  # 核查是否是日期格式if age <= 24:# 这里不需要根据海拔改变评分标准,但便于重用score_computing()函数,self.age24_keys用作参数两次return score_computing(original_amount,self.age24,self.age24_keys,self.age24_keys)elif 25 <= age <= 27:return score_computing(original_amount, self.age25_27, self.age25_27_keys, self.age25_27_keys)elif 28 <= age <= 30:return score_computing(original_amount, self.age28_30, self.age28_30_keys, self.age28_30_keys)elif 31 <= age <= 33:return score_computing(original_amount, self.age31_33, self.age31_33_keys, self.age31_33_keys)elif 34 <= age <= 36:return score_computing(original_amount, self.age34_36, self.age34_36_keys, self.age34_36_keys)elif 37 <= age <= 39:return score_computing(original_amount, self.age37_39, self.age37_39_keys, self.age37_39_keys)# 40~59elif 40 <= age <= 42:return score_computing(original_amount, self.age40_42, self.age40_42_keys, self.age40_42_keys)elif 43 <= age <= 45:return score_computing(original_amount, self.age43_45, self.age43_45_keys, self.age43_45_keys)elif 46 <= age <= 48:return score_computing(original_amount, self.age46_48, self.age46_48_keys, self.age46_48_keys)elif 49 <= age <= 51:return score_computing(original_amount, self.age49_51, self.age49_51_keys, self.age49_51_keys)elif 52 <= age <= 54:return score_computing(original_amount, self.age52_54, self.age52_54_keys, self.age52_54_keys)elif 55 <= age <= 57:return score_computing(original_amount, self.age55_57, self.age55_57_keys, self.age55_57_keys)elif 58 <= age <= 59:return score_computing(original_amount, self.age58_59, self.age58_59_keys, self.age58_59_keys)else:print('ERROR:男女平原3000米跑,原始成绩的数据类型须为时间(datetime.time)类型')if __name__ == "__main__":   # 测试本模块flatland_3km_female_std = Flatland3kmStandardData('女')result = flatland_3km_female_std.longrun_score_computing(25,dt.time(0,16,13))print(result)

8.对主程序training_performance.py进行修改。读取工作簿“人员参数设置”,分人员类别设置最低分数,如一类人员的最低分是65,低于65分即不及格,实际记0分;根据海拔参数,进行不同的实例化;判断性别后,先计算单杠成绩,接着计算仰卧起坐成绩,再计算蛇形跑成绩,最后计算3公里成绩,分别写入表中换算成绩的相应位置。

import openpyxl
import datetime as dt
from age_computing import age_computing                       # 导入年龄计算模块
from pullup_male import Pullup_standard_data                  # 导入男子引体向上成绩计算模块
from flex_arm_hang_female import Flex_arm_hang_standard_data  # 导入女子单杠曲臂悬垂的成绩计算模块
from situp_male import Situp_male_standard_data               # 导入男子仰卧起坐成绩计算模块
from situp_female import Situp_female_standard_data           # 导入女子仰卧起坐成绩计算模块
from serpentine_run_male import Serpentine_run_male_standard_data       # 导入男子蛇形跑成绩计算模块
from serpentine_run_female import Serpentine_run_female_standard_data   # 导入女子蛇形跑成绩计算模块
from highland2001up_3km_male import Highland2001up3kmMaleStandardData       # 导入男子高原2001~3000,3000米成绩计算模块
from highland3001up_3km_male import Highland3001up3kmMaleStandardData       # 导入男子高原3001~4000,3000米成绩计算模块
from highland2001up_3km_female import Highland2001up3kmFemaleStandardData       # 导入女子高原2001~3000,3000米成绩计算模块
from highland3001up_3km_female import Highland3001up3kmFemaleStandardData       # 导入女子高原2001~3000,3000米成绩计算模块
from flatland_3km import Flatland3kmStandardData                                # 导入男女平原3000米成绩计算模块wb=openpyxl.load_workbook('通用训练课目考核成绩计算.xlsx')
ws_training_score = wb['体能考核成绩']
ws_personnel_parameters = wb['人员参数设置']col_parameters = [c.value for c in list(ws_personnel_parameters.columns)[1][1:]]
staff_type = col_parameters[0] #人员类别
elevation = col_parameters[1]  #地区海拔if staff_type == '三类':lowest_score = 55
if staff_type == '二类':lowest_score = 60
if staff_type == '一类':lowest_score = 65pullup_sd = Pullup_standard_data()             # 实例化男子引体向上成绩计算
flexarmhang_sd = Flex_arm_hang_standard_data() # 实例化女子单杠曲臂悬垂成绩计算
situp_male = Situp_male_standard_data()        # 实例化男子仰卧起坐成绩计算
situp_female = Situp_female_standard_data()    # 实例化男子仰卧起坐成绩计算
serpentine_run_male = Serpentine_run_male_standard_data()      # 实例化男子蛇形跑成绩计算
serpentine_run_female = Serpentine_run_female_standard_data()  # 实例化女子蛇形跑成绩计算if elevation in range(0,2001):long_distance_run_male = Flatland3kmStandardData('男')    # 实例化男子平原3Km米跑计算模块long_distance_run_female = Flatland3kmStandardData('女')  # 实例化女子平原3Km米跑计算模块
elif elevation in range(2001,3001):long_distance_run_male = Highland2001up3kmMaleStandardData(elevation)   # 实例化男子高原海拔2001~3000米,3Km米跑计算模块long_distance_run_female = Highland2001up3kmFemaleStandardData(elevation)  # 实例化女子高原海拔2001~3000米,3Km米跑计算模块
elif elevation in range(3001,4001):long_distance_run_male = Highland3001up3kmMaleStandardData(elevation)   # 实例化男子高原海拔3001~4000米,3Km米跑计算模块long_distance_run_female = Highland3001up3kmFemaleStandardData(elevation)  # 实例化女子高原海拔3001~4000米,3Km米跑计算模块rngs = ws_training_score.iter_rows(min_row=6)
for row in rngs:gender = row[4].value          # 性别pullup = row[11].value         # 单杠原始数量situp =  row[7].value          # 仰卧起坐原始数量serpentine_run = row[9].value  # 蛇形跑原始数量long_distance_run = row[13].value  # 3Km跑原始时长if row[5].value:#print(row[5].value)age = age_computing(row[5].value)    #由出生日期计算年龄,精确到天row[6].value = ageif gender == '男':if row[6].value != None:  # 年龄不能为空if pullup != None:    # 单杆原始数不能为空score_pullup = pullup_sd.pullup_score_computing(age, pullup) # 计算男子单杠或俯卧撑成绩#print(row[0].value,pullup,row[12].value) # 测试if not score_pullup < lowest_score:row[12].value = score_pullupelse:row[12].value = 0if situp != None:     # 仰卧起坐原始数不能为空score_situp = situp_male.situp_male_score_computing(age, situp)  # 计算男子仰卧起坐成绩#print(row[0].value, situp, row[8].value)if not score_situp < lowest_score:row[8].value = score_situpelse:row[8].value = 0if serpentine_run != None:     # 蛇形跑原始数不能为空score_serpentine_run = serpentine_run_male.serpentine_run_male_score_computing(age, serpentine_run)  # 计算男子蛇形跑成绩#print(row[0].value, serpentine_run, row[10].value)if not score_serpentine_run < lowest_score:row[10].value = score_serpentine_runelse:row[10].value = 0if long_distance_run != None:     # 3Km跑原始时长不能为空score_long_run = long_distance_run_male.longrun_score_computing(age, long_distance_run)  # 计算男子3Km跑成绩#print(row[0].value, long_distance_run, row[14].value)if not score_long_run < lowest_score:row[14].value = score_long_runelse:row[14].value = 0elif gender == '女':if row[6].value != None:if pullup != None:  # 单杆原始数不能为空score_pullup = flexarmhang_sd.flex_arm_hang_score_computing(age, pullup) # 女子曲臂悬垂或俯卧撑成绩计算#print(row[0].value,pullup, row[12].value)if not score_pullup < lowest_score:row[12].value = score_pullupelse:row[12].value = 0if situp != None:     # 仰卧起坐原始数不能为空score_situp = situp_female.situp_female_score_computing(age, situp)  # 计算女子仰卧起坐成绩#print(row[0].value, situp, row[8].value)if not score_situp < lowest_score:row[8].value = score_situpelse:row[8].value = 0if serpentine_run != None:     # 蛇形跑原始数不能为空score_serpentine_run = serpentine_run_female.serpentine_run_female_score_computing(age, serpentine_run)  # 计算女子蛇形跑成绩#print(row[0].value, serpentine_run, row[10].value)if not score_serpentine_run < lowest_score:row[10].value = score_serpentine_runelse:row[10].value = 0if long_distance_run != None:     # 3Km跑原始时长不能为空score_long_run = long_distance_run_female.longrun_score_computing(age, long_distance_run)  # 计算女子3Km跑成绩#print(row[0].value, long_distance_run, row[14].value)if not score_long_run < lowest_score:row[14].value = score_long_runelse:row[14].value = 0else:    # 性别输入有误print('序号%d %s 的性别填写错误'%(row[0].value,row[1].value))wb.save('计算结果.xlsx')
print('计算已完成!')

运行后,生成文件“计算结果.xlsx”如下:
海拔3701米3公里的计算结果

到此,我们成功实现了最复杂的3公里成绩计算的功能。

军事体能考核成绩评定系统下载

军事体能考核成绩评定系统全套Python源码下载

这篇关于Python+Excel数据分析实战:军事体能考核成绩评定(七)3公里计算的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/393444

相关文章

Python版本信息获取方法详解与实战

《Python版本信息获取方法详解与实战》在Python开发中,获取Python版本号是调试、兼容性检查和版本控制的重要基础操作,本文详细介绍了如何使用sys和platform模块获取Python的主... 目录1. python版本号获取基础2. 使用sys模块获取版本信息2.1 sys模块概述2.1.1

一文详解Python如何开发游戏

《一文详解Python如何开发游戏》Python是一种非常流行的编程语言,也可以用来开发游戏模组,:本文主要介绍Python如何开发游戏的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录一、python简介二、Python 开发 2D 游戏的优劣势优势缺点三、Python 开发 3D

Python函数作用域与闭包举例深度解析

《Python函数作用域与闭包举例深度解析》Python函数的作用域规则和闭包是编程中的关键概念,它们决定了变量的访问和生命周期,:本文主要介绍Python函数作用域与闭包的相关资料,文中通过代码... 目录1. 基础作用域访问示例1:访问全局变量示例2:访问外层函数变量2. 闭包基础示例3:简单闭包示例4

Python实现字典转字符串的五种方法

《Python实现字典转字符串的五种方法》本文介绍了在Python中如何将字典数据结构转换为字符串格式的多种方法,首先可以通过内置的str()函数进行简单转换;其次利用ison.dumps()函数能够... 目录1、使用json模块的dumps方法:2、使用str方法:3、使用循环和字符串拼接:4、使用字符

Python版本与package版本兼容性检查方法总结

《Python版本与package版本兼容性检查方法总结》:本文主要介绍Python版本与package版本兼容性检查方法的相关资料,文中提供四种检查方法,分别是pip查询、conda管理、PyP... 目录引言为什么会出现兼容性问题方法一:用 pip 官方命令查询可用版本方法二:conda 管理包环境方法

基于Python开发Windows自动更新控制工具

《基于Python开发Windows自动更新控制工具》在当今数字化时代,操作系统更新已成为计算机维护的重要组成部分,本文介绍一款基于Python和PyQt5的Windows自动更新控制工具,有需要的可... 目录设计原理与技术实现系统架构概述数学建模工具界面完整代码实现技术深度分析多层级控制理论服务层控制注

pycharm跑python项目易出错的问题总结

《pycharm跑python项目易出错的问题总结》:本文主要介绍pycharm跑python项目易出错问题的相关资料,当你在PyCharm中运行Python程序时遇到报错,可以按照以下步骤进行排... 1. 一定不要在pycharm终端里面创建环境安装别人的项目子模块等,有可能出现的问题就是你不报错都安装

Python打包成exe常用的四种方法小结

《Python打包成exe常用的四种方法小结》本文主要介绍了Python打包成exe常用的四种方法,包括PyInstaller、cx_Freeze、Py2exe、Nuitka,文中通过示例代码介绍的非... 目录一.PyInstaller11.安装:2. PyInstaller常用参数下面是pyinstal

Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题

《Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题》在爬虫工程里,“HTTPS”是绕不开的话题,HTTPS为传输加密提供保护,同时也给爬虫带来证书校验、... 目录一、核心问题与优先级检查(先问三件事)二、基础示例:requests 与证书处理三、高并发选型:

Python中isinstance()函数原理解释及详细用法示例

《Python中isinstance()函数原理解释及详细用法示例》isinstance()是Python内置的一个非常有用的函数,用于检查一个对象是否属于指定的类型或类型元组中的某一个类型,它是Py... 目录python中isinstance()函数原理解释及详细用法指南一、isinstance()函数