Skip to content

Instantly share code, notes, and snippets.

@1682105
Last active May 29, 2025 06:22
Show Gist options
  • Save 1682105/6c4eb92f53eca012294db7a8d375c031 to your computer and use it in GitHub Desktop.
Save 1682105/6c4eb92f53eca012294db7a8d375c031 to your computer and use it in GitHub Desktop.
5.29函数练习
# 定义一个BMI函数
def bmi(height, weight):
"""bmi公式,体重除以身高的平方"""
return weight / (height * height)
height = float(input('请输入身高(米):'))
weight = float(input('请输入体重(公斤):'))
bmi_value = bmi(height, weight)
if bmi_value < 18.5:
print("bmi低于18.5,过轻!")
elif 18.5 <= bmi_value <= 23.9:
print("bmi在18.5-23.9之间,正常!")
elif 23.9 < bmi_value <= 28.9:
print("bmi高于23.9,过重!")
elif 28.9 < bmi_value <= 32.9:
print("bmi高于28.9,肥胖!")
else:
print("bmi高于32.9, 严重肥胖!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment