实战一:创建一个python文件,然后在文件中定义一个名称为fun_bmi_upgrade的函数,该函数包括一个可变参数,用于指定包括姓名、身高和体重的测试人信息,在该函数中将根据测试人信息计算BMI指数,并输出结果,最后在函数体外定义一个列表,并且将该列表作为fun_bmi_upgrade()函数的参数调用。
BMI公式及输出要求:bmi = weight/(height*height)
def fun_bmi_upgrade(*list):
for information in list:
for item in information:
person = item[0]
height = item[1]
weight = item[2]
bmi=weight/(height*height) # 用于计算BMI指数,公式为“体重/身高的平方”
print(person + "的身高:" + str(height) + "米 \t 体重:" + str(weight) + "千克")
print(person + "的BMI指数为:"+str(bmi)) # 输出BMI指数
# 判断身材是否合理
if bmi<18.5:
print("您的体重过轻 ~@_@~\n")
if bmi>=18.5 and bmi<24.9:
print("正常范围,注意保持 (-_-)\n")
if bmi>=24.9 and bmi<29.9:
print("您的体重过重 ~@_@~\n")
if bmi>=29.9:
print("肥胖 ^@_@^\n")
#调用函数******#
list_w = [(‘绮梦’,1.70,65),(‘零语’,1.77,50),(‘黛兰’,1.72,66)]
list_m = [(‘梓轩’,1.80,75),(‘冷伊一’,1.75,70)]
fun_bmi_upgrade(list_w,list_m) # 调用函数指定可变参数