Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

โปรแกรม Python คำนวณ BMI (Body Mass Index)


คำนวณดัชนีมวลกาย (BMI) จากส่วนสูง (เมตร) และน้ำหนัก (กิโลกรัม)

สูตร

BMI = weight / (height × height)

โค้ดตัวอย่าง

height = float(input("Enter your height (m): "))
weight = float(input("Enter your weight (kg): "))
bmi = weight / (height * height)
print("Your BMI is:", round(bmi, 2))

ผลลัพธ์

Enter your height (m): 5.8
Enter your weight (kg): 64
Your BMI is: 1.9