roberthsu2003 / __2024_05_05_sunday__

AI 人工智慧開發入門_python
29 stars 2 forks source link

計算BMI #12

Closed minfoung closed 2 months ago

minfoung commented 2 months ago
import  pyinputplus as pypi

name = pypi.inputStr("請輸入您的姓名: ")
print(name)
height = pypi.inputInt("請輸入您的身高(cm): ", min=50, max=250)
print(height)
weight = pypi.inputInt("請輸入您的體重(kg): ", min=0, max=200)
print(weight)

BMI = weight / (height / 100) ** 2
if BMI < 18.5:
    rate = "過輕"
elif BMI < 24:
    rate = "正常"
elif BMI < 27:
    rate = "過重"
elif BMI < 30:
    rate = "輕度肥胖"
elif BMI < 35:
    rate = "中度肥胖"
else:
    rate = "重度肥胖"

print(f"您的姓名為 {name}\n您的BMI值為 {BMI}\n您屬於 {rate} 範圍")

image