def MultAll_Int(start, end): """此函数所接受的变量: start:int型 end:int型 此函数的作用: 在[start,end]区间内的所有int型数字都相乘起来,并返回相乘数值 此函数返回值: int型""" if type(start) != int and type(end) != int: helper.ExitMSG_Return( "MultAll_Int(start , end)", "\n\t\t\t\t\t\t\t1.start必须为int型" "\n\t\t\t\t\t\t\t2.end必须为int型") elif type(start) != int: helper.ExitMSG_Return("MultAll_Int(start , end)", "start必须为int型") elif type(end) != int: helper.ExitMSG_Return("MultAll_Int(start , end)", "end必须为int型") elif start >= end: helper.ExitMSG_Return("MultAll_Int(start , end)", "开头的数值不能大于末尾的数值") a = [] start = int(start) end = int(end) for i in range(start, end + 1): a.append(i) MultList = 1 for j in a: MultList *= j return MultList
def Similarity_BTwen_Two_Number(num1, num2, rAnge): rAnge = 10**rAnge if rAnge < abs(num1 - num2): helper.ExitMSG_Return("Similarity_BTwen_Two_Number(num1, num2, range)", "range的数值必须大于(num1-num2)的绝对值") distance = abs(num1 - num2) return (rAnge - distance) / rAnge
def Gi(number, lst): if len(lst) <= 17: average = Average_Number(lst) SD = Standard_Deviation(lst) gi = (abs(number - average)) / SD return gi else: helper.ExitMSG_Return("Gi(number, lst)", "Gi值检测现阶段只允许长度小于等于17的列表")
def Geometric_Progression(a1, q, n, result_flag): if result_flag == Geometric_Progression_Enum.Sn: if q != 1: Sn = a1 * (1 - q**n) / (1 - q) if round(Sn) == Sn: return round(Sn) else: return Sn else: helper.ExitMSG_Return( "Arithmetic_Progression(a1, n, d, result_flag=)", "q不能等于1") elif result_flag == Geometric_Progression_Enum.an: an = a1 * q**(n - 1) return an else: helper.ExitMSG_Return("Arithmetic_Progression(a1, n, d, result_flag=)", "错误")
def Healthy_Weight_Judge_By_BMI(BMI , Language = 'Chinese'): """此函数所接受的变量: BMI:float型 Language:str型 此函数的作用: 通过BMI数值判断其体重判断,并返回 若Language为Chinese,则返回汉字 若Language为English,则返回英文 Language默认值为Chinese 此函数返回值: BMI_Judge:str型""" if type(BMI) == int: BMI = float(BMI) if type(BMI) != float: helper.ExitMSG_Return("Exercise_Healthy_Weight_Judge_By_BMI(BMI , Language = 'Chinese')", "BMI必须为float型或int型") if Language == 'Chinese': if BMI <= 0: return 'BMI数值错误' elif BMI < 18.5: return '过轻' elif 18.5 <= BMI <= 23.9: return '正常' elif 24 <= BMI <= 27: return '过重' elif 28 <= BMI <= 32: return '肥胖' else: return '非常肥胖' elif Language == 'English': if BMI <= 0: return 'BMI Error' elif BMI < 18.5: return 'Underweight' elif 18.5 <= BMI <= 23.9: return 'Normal' elif 24 <= BMI <= 27: return 'Overweight' elif 28 <= BMI <= 32: return 'Fat' else: return 'Veryfat' else: return helper.ExitMSG_Return("Exercise_Healthy_Weight_Judge_By_BMI(BMI , Language = 'Chinese')", "Language必须为Chinese或English")
def SumAll_Float(start, end, addNum=1.0): """此函数所接受的变量: start:float型 end:float型 add_num:float型(add_num若不给它赋值,则默认是1.0) 此函数的作用: 把[start,end)区间内的所有数字,间隔为addNum的数字加起来,并返回总值 此函数返回值: float型""" if type(start) != float and type(end) != float and type(addNum) != float: helper.ExitMSG_Return( "SumAll_Float(start, end, addNum = 1.0)", "\n\t\t\t\t\t\t\t\t\t\t\t1.start必须为float型" "\n\t\t\t\t\t\t\t\t\t\t\t2.end必须为float型" "\n\t\t\t\t\t\t\t\t\t\t\t3.add_num必须为float型") elif type(start) != float and type(end) != float: helper.ExitMSG_Return( "SumAll_Float(start, end, addNum = 1.0)", "\n\t\t\t\t\t\t\t\t\t\t\t1.start必须为float型" "\n\t\t\t\t\t\t\t\t\t\t\t2.end必须为float型") elif type(start) != float and type(addNum) != float: helper.ExitMSG_Return( "SumAll_Float(start, end, addNum = 1.0)", "\n\t\t\t\t\t\t\t\t\t\t\t1.start必须为float型" "\n\t\t\t\t\t\t\t\t\t\t\t2.add_num必须为float型") elif type(end) != float and type(addNum) != float: helper.ExitMSG_Return( "SumAll_Float(start, end, addNum = 1.0)", "\n\t\t\t\t\t\t\t\t\t\t\t1.end必须为float型" "\n\t\t\t\t\t\t\t\t\t\t\t2.add_num必须为float型") elif type(start) != float: helper.ExitMSG_Return("SumAll_Float(start, end, addNum = 1.0)", "start必须为float型") elif type(end) != float: helper.ExitMSG_Return("SumAll_Float(start, end, addNum = 1.0)", "end必须为float型") elif type(addNum) != float: helper.ExitMSG_Return("SumAll_Float(start, end, addNum = 1.0)", "add_num必须为float型") elif start >= end: helper.ExitMSG_Return("SumAll_Float(start, end, addNum = 1.0)", "开头的数值不能大于末尾的数值") elif addNum > end - start: helper.ExitMSG_Return("SumAll_Float(start, end, addNum = 1.0)", "间隔的数值不能超过末尾的数值减去开头的数值") Sum = Arithmetic_Progression(start, addNum, (end - start) / addNum, result_flag=Arithmetic_Progression_Enum.Sn) return Sum
def Narcissistic_Number_Judge(number): if type(number) != int: helper.ExitMSG_Return("Narcissistic_Number_Judge(number)", "number必须为int型") number_length = Number_Figure(number) number_lst = helper.Number_Separate(number) for i in range(0, len(number_lst)): number_lst[i] = number_lst[i]**number_length return sum(number_lst) == number
def Even_Judge(number): """此函数所接受的变量: number:int型 此函数的作用: 判断数字number是否为偶数,若是则返回True,反之则返回False 此函数返回值: 布尔类型(True or False)""" if type(number) != int: helper.ExitMSG_Return("Even_Judge(number)", "number必须为int型") return number % 2 == 0
def Sex_EnumToCN(Sex_Enum): """此函数所接受的变量: Sex_Enum:枚举类型 此函数的作用: 通过性别枚举,返回其相对应的str型性别,为汉字 此函数返回值: Sex:str型""" if type(Sex_Enum) != Enum: helper.ExitMSG_Return("Exercise_Sex_EnumToCN(Sex_Enum)", "Sex_Enum必须为Exercise_Enum类型") if Sex_Enum == Enum.SEX_MALE: return "男" elif Sex_Enum == Enum.SEX_FEMALE: return "女"
def Arithmetic_Progression(a1, d, n, result_flag): if result_flag == Arithmetic_Progression_Enum.Sn: Sn = n * a1 + (n * d * (n - 1)) / 2 if round(Sn) == Sn: return round(Sn) else: return Sn elif result_flag == Arithmetic_Progression_Enum.an: an = a1 + (n - 1) * d return an else: helper.ExitMSG_Return("Arithmetic_Progression(a1, n, d, result_flag=)", "错误")
def SumAll_Int(start, end): """此函数所接受的变量: start:int型 end:int型 此函数的作用: 在[start,end]区间内的所有int型数字都相加起来,并返回总值 此函数返回值: int型""" if type(start) != int and type(end) != int: helper.ExitMSG_Return("SumAll_Int(start , end)", "start必须为int型,end必须为int型") elif type(start) != int: helper.ExitMSG_Return("SumAll_Int(start , end)", "start必须为int型") elif type(end) != int: helper.ExitMSG_Return("SumAll_Int(start , end)", "end必须为int型") elif start >= end: helper.ExitMSG_Return("SumAll_Int(start , end)", "开头的数值不能大于末尾的数值") Sum = Arithmetic_Progression(start, 1, end - start + 1, result_flag=Arithmetic_Progression_Enum.Sn) return round(Sum)
def Morphy_EnumToCN(Morphy_Enum): """此函数所接受的变量: Morpy_Enum:枚举类型 此函数的作用: 通过胚型枚举,返回其相对应的str型胚型,为汉字 此函数返回值: Morphy:str型""" if type(Morphy_Enum) != Enum: helper.ExitMSG_Return("Exercise_Morphy_EnumToCN(Morphy_Enum)", "Morphy_Enum必须为Exercise_Enum型") if Morphy_Enum == Enum.MORPHY_ECTOMORPHY: return "外胚型" elif Morphy_Enum == Enum.MORPHY_MESOMORPHY: return "中胚型" elif Morphy_Enum == Enum.MORPHY_ENDOMORPHY: return "内胚型"
def MIS_EnumToMath(MIS_Enum): """此函数所接受的变量: MIS_Enum:枚举类型 此函数的作用: 通过运动系数级别枚举,返回其相对应的运动系数,为int型 此函数返回值: MIS:int型""" if type(MIS_Enum) != Enum: helper.ExitMSG_Return("Exercise_MIS_EnumToMath(MIS_Enum)", "MIS_Enum必须为Exercise_Enum类型") if MIS_Enum == Enum.MIS_LEVEL_1: return 1.0 elif MIS_Enum == Enum.MIS_LEVEL_2: return 1.2 elif MIS_Enum == Enum.MIS_LEVEL_3: return 1.4 elif MIS_Enum == Enum.MIS_LEVEL_4: return 1.6 elif MIS_Enum == Enum.MIS_LEVEL_5: return 1.8 elif MIS_Enum == Enum.MIS_LEVEL_6: return 2.0