定义一个ccc.py文件模块,包含如下三个函数。 (1)函数参数为父母的身高,返回结果为使用公式预测的子女身高元组,具体代码类似于work2_07.py。 (2)函数参数为布罗卡公式所需的成年人的身高和体重,返回值为判断结果,具体代码类似于work4_08.py。 (3)函数参数为世界卫生组织计算方法所需的成年人性别、身高和体重,返回值为判断结果,具体代码类似于work4_09.py。 (4)在文件模块内部编写测试代码,并在work7_01.py中使用ccc模块。
时间: 2023-11-22 19:52:00 浏览: 215
# 在ccc.py文件模块中定义三个函数
def predict_height(parent_height):
son_height = (parent_height[0] + parent_height[1]) * 0.54
daughter_height = (parent_height[0] * 0.923 + parent_height[1]) / 2
return son_height, daughter_height
def broca_formula(height, weight):
standard_weight = (height - 100) * 0.9
if weight < standard_weight * 0.9:
return "偏轻"
elif weight > standard_weight * 1.1:
return "偏重"
else:
return "正常"
def who_formula(gender, height, weight):
BMI = weight / (height / 100) ** 2
if gender == "男":
if BMI < 20.7:
return "偏轻"
elif BMI > 26.4:
return "偏重"
else:
return "正常"
else:
if BMI < 19.1:
return "偏轻"
elif BMI > 25.8:
return "偏重"
else:
return "正常"
# 编写测试代码
if __name__ == "__main__":
# 测试predict_height函数
print(predict_height((175, 165))) # 输出(94.5, 168.5)
# 测试broca_formula函数
print(broca_formula(175, 70)) # 输出"正常"
print(broca_formula(175, 60)) # 输出"偏轻"
print(broca_formula(175, 85)) # 输出"偏重"
# 测试who_formula函数
print(who_formula("男", 175, 70)) # 输出"正常"
print(who_formula("女", 165, 55)) # 输出"正常"
阅读全文
相关推荐



















